Skip to content

Commit f1f8d7e

Browse files
Schuemime-no-dev
authored andcommitted
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.
1 parent da798c7 commit f1f8d7e

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

Diff for: libraries/WiFi/src/WiFiUdp.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ int WiFiUDP::parsePacket(){
221221
}
222222
remote_ip = IPAddress(si_other.sin_addr.s_addr);
223223
remote_port = ntohs(si_other.sin_port);
224+
if (len == 0) return 0;
224225
rx_buffer = new cbuf(len);
225226
rx_buffer->write(buf, len);
226227
delete[] buf;
@@ -264,6 +265,7 @@ int WiFiUDP::peek(){
264265
}
265266

266267
void WiFiUDP::flush(){
268+
if(!rx_buffer) return;
267269
cbuf *b = rx_buffer;
268270
rx_buffer = 0;
269271
delete b;

0 commit comments

Comments
 (0)