From c0b9321407d99eedbdd52a75bbd19491ae432fff Mon Sep 17 00:00:00 2001 From: Georg Hopp Date: Wed, 13 Aug 2014 07:17:14 +0100 Subject: [PATCH] the stack overflow issue was related to a not correctly initialized external variable (size). Use a ternery to prevent to large size values. --- src/udp_socket.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/udp_socket.c b/src/udp_socket.c index 05b4944..f1e18b0 100644 --- a/src/udp_socket.c +++ b/src/udp_socket.c @@ -51,12 +51,11 @@ static TR_RemoteData udpSocketRecv(TR_Socket this, size_t size) { - unsigned char * buffer = TR_malloc(size); + unsigned char buffer[size>8192 ? 8192 : size]; ssize_t received; TR_RemoteData rdata; - TR_Socket remote; + TR_Socket remote = TR_new(TR_UdpSocket, this->log, NULL, 0, 0); - remote = TR_new(TR_UdpSocket, this->log, NULL, 0, 0); remote->addrlen = this->addrlen; received = recvfrom( @@ -73,8 +72,6 @@ udpSocketRecv(TR_Socket this, size_t size) rdata = TR_new(TR_RemoteData, buffer, received, remote); } - TR_MEM_FREE(buffer); - rdata->free_remote = 1; return rdata;