ethernet_input: check for minimum packet length to prevent assertions from firing.

This commit is contained in:
goldsimon 2011-03-29 07:55:16 +00:00
parent 11b1c9f19f
commit 36c1750b8f

View File

@ -1219,6 +1219,13 @@ ethernet_input(struct pbuf *p, struct netif *netif)
struct eth_hdr* ethhdr;
u16_t type;
if (p->tot_len <= SIZEOF_ETH_HDR) {
/* a packet with only an ethernet header (or less) is not valid */
ETHARP_STATS_INC(etharp.proterr);
ETHARP_STATS_INC(etharp.drop);
goto free_and_return;
}
/* points to packet payload, which starts with an Ethernet header */
ethhdr = (struct eth_hdr *)p->payload;
LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE,
@ -1232,6 +1239,7 @@ ethernet_input(struct pbuf *p, struct netif *netif)
type = ethhdr->type;
#if ETHARP_SUPPORT_VLAN
if (type == PP_HTONS(ETHTYPE_VLAN)) {
/* @todo: check for minimum packet length */
struct eth_vlan_hdr *vlan = (struct eth_vlan_hdr*)(((char*)ethhdr) + SIZEOF_ETH_HDR);
#ifdef ETHARP_VLAN_CHECK /* if not, allow all VLANs */
if (VLAN_ID(vlan) != ETHARP_VLAN_CHECK) {