Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WiFiUDP:parsePacket() Crashfix #7847

Merged
merged 2 commits into from
Feb 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions libraries/WiFi/src/WiFiUdp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include "WiFiUdp.h"
#include <new> //std::nothrow
#include <lwip/sockets.h>
#include <lwip/netdb.h>
#include <errno.h>
Expand Down Expand Up @@ -207,12 +209,12 @@ int WiFiUDP::parsePacket(){
return 0;
struct sockaddr_in si_other;
int slen = sizeof(si_other) , len;
char * buf = new char[1460];
if(!buf){
char *buf = (char *)malloc(1460);
mrengineer7777 marked this conversation as resolved.
Show resolved Hide resolved
if(!buf) {
return 0;
}
if ((len = recvfrom(udp_server, buf, 1460, MSG_DONTWAIT, (struct sockaddr *) &si_other, (socklen_t *)&slen)) == -1){
delete[] buf;
free(buf);
mrengineer7777 marked this conversation as resolved.
Show resolved Hide resolved
if(errno == EWOULDBLOCK){
return 0;
}
Expand All @@ -222,10 +224,10 @@ int WiFiUDP::parsePacket(){
remote_ip = IPAddress(si_other.sin_addr.s_addr);
remote_port = ntohs(si_other.sin_port);
if (len > 0) {
rx_buffer = new cbuf(len);
rx_buffer = new(std::nothrow) cbuf(len);
rx_buffer->write(buf, len);
}
delete[] buf;
free(buf);
mrengineer7777 marked this conversation as resolved.
Show resolved Hide resolved
return len;
}

Expand Down