Skip to content

Commit

Permalink
cpu/esp8266: fix pbuf length check in esp_wifi
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gschorcht committed Jan 24, 2019
1 parent 88c65af commit 49f06ef
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions cpu/esp8266/esp-wifi/esp_wifi_netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down

0 comments on commit 49f06ef

Please sign in to comment.