diff --git a/src/core/tcp_in.c b/src/core/tcp_in.c index a4c3cd4e..6af24014 100644 --- a/src/core/tcp_in.c +++ b/src/core/tcp_in.c @@ -113,7 +113,16 @@ tcp_input(struct pbuf *p, struct netif *inp) iphdr = p->payload; tcphdr = (struct tcp_hdr *)((u8_t *)p->payload + IPH_HL(iphdr) * 4); - pbuf_header(p, -((s16_t)(IPH_HL(iphdr) * 4))); + if (pbuf_header(p, -((s16_t)(IPH_HL(iphdr) * 4)))) { + /* drop short packets */ + DEBUGF(TCP_INPUT_DEBUG, ("tcp_input: short packet (%u bytes) discarded\n", p->tot_len)); +#ifdef TCP_STATS + ++lwip_stats.tcp.lenerr; + ++lwip_stats.tcp.drop; +#endif /* TCP_STATS */ + pbuf_free(p); + return; + } /* Don't even process incoming broadcasts/multicasts. */ if(ip_addr_isbroadcast(&(iphdr->dest), &(inp->netmask)) || diff --git a/src/core/udp.c b/src/core/udp.c index 759b4090..b000ed18 100644 --- a/src/core/udp.c +++ b/src/core/udp.c @@ -175,7 +175,17 @@ udp_input(struct pbuf *p, struct netif *inp) iphdr = p->payload; - pbuf_header(p, -((s16_t)(UDP_HLEN + IPH_HL(iphdr) * 4))); + if (pbuf_header(p, -((s16_t)(UDP_HLEN + IPH_HL(iphdr) * 4)))) { + /* drop short packets */ + DEBUGF(UDP_DEBUG, ("udp_input: short UDP datagram (%u bytes) discarded\n", p->tot_len)); +#ifdef UDP_STATS + ++lwip_stats.udp.lenerr; + ++lwip_stats.udp.drop; +#endif /* UDP_STATS */ + snmp_inc_udpinerrors(); + pbuf_free(p); + goto end; + } udphdr = (struct udp_hdr *)((u8_t *)p->payload - UDP_HLEN);