From f1f8d7e306bf31d292550fce9a3ce463da6a58f1 Mon Sep 17 00:00:00 2001 From: Schuemi <33527753+Schuemi@users.noreply.github.com> Date: Tue, 24 Jul 2018 19:52:42 +0200 Subject: [PATCH] Packet with zero data length (#1659) 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 4e6db72a..acc7a183 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;