Unverified Commit 6d64a3b6 authored by David McCurley's avatar David McCurley Committed by GitHub

WiFiUDP:parsePacket() Crashfix (#7847)

* Update WiFiUdp.cpp

* Update WiFiUdp.cpp
parent b8ea455f
......@@ -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>
......@@ -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);
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);
if(errno == EWOULDBLOCK){
return 0;
}
......@@ -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);
return len;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment