mirror of
https://github.com/openshwprojects/OpenBK7231T_App.git
synced 2026-02-19 16:22:07 +01:00
HTTP TCP server: fix realloc failure handling to prevent request buffer leak (#1990)
* Update http_tcp_server.c * Update new_tcp_server.c
This commit is contained in:
@@ -95,11 +95,12 @@ static void tcp_client_thread(beken_thread_arg_t arg)
|
||||
}
|
||||
// grow by 1024
|
||||
request.receivedLenmax += 1024;
|
||||
request.received = (char*)realloc(request.received, request.receivedLenmax+2);
|
||||
if (request.received == NULL) {
|
||||
char *newbuf = (char*)realloc(request.received, request.receivedLenmax + 2);
|
||||
if (newbuf == NULL) {
|
||||
// no memory
|
||||
return;
|
||||
goto exit;
|
||||
}
|
||||
request.received = buf = newbuf;
|
||||
}
|
||||
request.received[request.receivedLen] = 0;
|
||||
#endif
|
||||
|
||||
@@ -85,12 +85,13 @@ static void tcp_client_thread(tcp_thread_t* arg)
|
||||
}
|
||||
// grow by INCOMING_BUFFER_SIZE
|
||||
request.receivedLenmax += INCOMING_BUFFER_SIZE;
|
||||
request.received = (char*)realloc(request.received, request.receivedLenmax + 2);
|
||||
if(request.received == NULL)
|
||||
char *newbuf = (char*)realloc(request.received, request.receivedLenmax + 2);
|
||||
if(newbuf == NULL)
|
||||
{
|
||||
// no memory
|
||||
goto exit;
|
||||
}
|
||||
request.received = buf = newbuf;
|
||||
}
|
||||
request.received[request.receivedLen] = 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user