From 49f06efd38ead041d2b050919c3983ab22b8db80 Mon Sep 17 00:00:00 2001 From: Gunar Schorcht <gunar@schorcht.net> Date: Thu, 24 Jan 2019 09:51:43 +0100 Subject: [PATCH] cpu/esp8266: fix pbuf length check in esp_wifi When the size of a received frame is checked, always the total length should be used instead of the length of the first lwIP pbuf in the pbuf chain. Otherwise, the check that the length does not exceed ETHERNET_MAX_LEN will always be true since the maximum size of one lwIP pbuf in a pbuf chain is 512 bytes. --- cpu/esp8266/esp-wifi/esp_wifi_netdev.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cpu/esp8266/esp-wifi/esp_wifi_netdev.c b/cpu/esp8266/esp-wifi/esp_wifi_netdev.c index 8fa246daf2..0219396857 100644 --- a/cpu/esp8266/esp-wifi/esp_wifi_netdev.c +++ b/cpu/esp8266/esp-wifi/esp_wifi_netdev.c @@ -185,9 +185,9 @@ void IRAM _esp_wifi_recv_cb(struct pbuf *pb, struct netif *netif) critical_enter(); /* first, check packet buffer for the minimum packet size */ - if (pb->len < sizeof(ethernet_hdr_t)) { + if (pb->tot_len < sizeof(ethernet_hdr_t)) { ESP_WIFI_DEBUG("frame length is less than the size of an Ethernet" - "header (%u < %u)", pb->len, sizeof(ethernet_hdr_t)); + "header (%u < %u)", pb->tot_len, sizeof(ethernet_hdr_t)); pbuf_free(pb); _in_esp_wifi_recv_cb = false; critical_exit(); @@ -207,9 +207,9 @@ void IRAM _esp_wifi_recv_cb(struct pbuf *pb, struct netif *netif) } /* check whether packet buffer fits into receive buffer */ - if (pb->len > ETHERNET_MAX_LEN) { + if (pb->tot_len > ETHERNET_MAX_LEN) { ESP_WIFI_DEBUG("frame length is greater than the maximum size of an " - "Ethernet frame (%u > %u)", pb->len, ETHERNET_MAX_LEN); + "Ethernet frame (%u > %u)", pb->tot_len, ETHERNET_MAX_LEN); pbuf_free(pb); _in_esp_wifi_recv_cb = false; critical_exit(); -- GitLab