diff --git a/src/slirp.c b/src/slirp.c index b0194cb..3fd6f68 100644 --- a/src/slirp.c +++ b/src/slirp.c @@ -890,20 +890,22 @@ static int if_encap6(Slirp *slirp, struct mbuf *ifm, struct ethhdr *eh, */ int if_encap(Slirp *slirp, struct mbuf *ifm) { - uint8_t buf[1600]; - struct ethhdr *eh = (struct ethhdr *)buf; + uint8_t *buf; + struct ethhdr *eh; uint8_t ethaddr[ETH_ALEN]; const struct ip *iph = (const struct ip *)ifm->m_data; int ret; - if (ifm->m_len + ETH_HLEN > sizeof(buf)) { - return 1; - } + buf = g_malloc(ifm->m_len + ETH_HLEN); + if (!buf) + return 0; + eh = (struct ethhdr *)buf; switch (iph->ip_v) { case IPVERSION: ret = if_encap4(slirp, ifm, eh, ethaddr); if (ret < 2) { + g_free(buf); return ret; } break; @@ -911,6 +913,7 @@ int if_encap(Slirp *slirp, struct mbuf *ifm) case IP6VERSION: ret = if_encap6(slirp, ifm, eh, ethaddr); if (ret < 2) { + g_free(buf); return ret; } break; @@ -929,6 +932,7 @@ int if_encap(Slirp *slirp, struct mbuf *ifm) eh->h_dest[5]); memcpy(buf + sizeof(struct ethhdr), ifm->m_data, ifm->m_len); slirp_send_packet_all(slirp, buf, ifm->m_len + ETH_HLEN); + g_free(buf); return 1; }