Skip to content

Commit

Permalink
Packet with zero data length (#1659)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Schuemi authored and me-no-dev committed Jul 24, 2018
1 parent da798c7 commit f1f8d7e
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions libraries/WiFi/src/WiFiUdp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -264,6 +265,7 @@ int WiFiUDP::peek(){
}

void WiFiUDP::flush(){
if(!rx_buffer) return;
cbuf *b = rx_buffer;
rx_buffer = 0;
delete b;
Expand Down

0 comments on commit f1f8d7e

Please sign in to comment.