From e1ebc0a2c13511fa6457d4f13eeb82ee6c64464b Mon Sep 17 00:00:00 2001 From: Schuemi <33527753+Schuemi@users.noreply.github.com> Date: Fri, 20 Jul 2018 16:03:14 +0200 Subject: [PATCH] Packet with zero data length If you receive a package with a data length of zero, parsePacket returns 0, but rx_buffer will exist. So if another parsePacket with no read access returns to zeros, there is still data that can be read. This example would not work: https://www.arduino.cc/en/Reference/EthernetUDPParsePacket Also I added a check if rx_buffer exit when you try to flush it. --- libraries/WiFi/src/WiFiUdp.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libraries/WiFi/src/WiFiUdp.cpp b/libraries/WiFi/src/WiFiUdp.cpp index 4e6db72a614..acc7a1834a7 100644 --- a/libraries/WiFi/src/WiFiUdp.cpp +++ b/libraries/WiFi/src/WiFiUdp.cpp @@ -221,6 +221,7 @@ int WiFiUDP::parsePacket(){ } remote_ip = IPAddress(si_other.sin_addr.s_addr); remote_port = ntohs(si_other.sin_port); + if (len == 0) return 0; rx_buffer = new cbuf(len); rx_buffer->write(buf, len); delete[] buf; @@ -264,6 +265,7 @@ int WiFiUDP::peek(){ } void WiFiUDP::flush(){ + if(!rx_buffer) return; cbuf *b = rx_buffer; rx_buffer = 0; delete b;