Skip to content

Commit 3d687a7

Browse files
committed
net_http: avoid realloc(p, 0) leaving response->data dangling on empty body
1 parent 1224324 commit 3d687a7

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

libretro-common/net/net_http.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,7 +1383,7 @@ static ssize_t net_http_receive_header(struct http_t *state, ssize_t len)
13831383
{
13841384
len = response->pos;
13851385
response->pos = 0;
1386-
if (response->bodytype == T_LEN)
1386+
if (response->bodytype == T_LEN && response->len > 0)
13871387
{
13881388
/* Use a tmp pointer so a realloc failure does not leak the
13891389
* original buffer AND leave response->data NULL for later
@@ -1428,7 +1428,7 @@ static bool net_http_receive_body(struct http_t *state, ssize_t newlen)
14281428
if (response->bodytype != T_FULL)
14291429
return false;
14301430
response->part = P_DONE;
1431-
if (response->buflen != response->len)
1431+
if (response->buflen != response->len && response->len > 0)
14321432
{
14331433
/* Shrink response->data from buflen bytes to len bytes.
14341434
* Use a tmp pointer so a realloc() failure (rare on shrink
@@ -1535,7 +1535,7 @@ static bool net_http_receive_body(struct http_t *state, ssize_t newlen)
15351535
else if (response->pos == response->len)
15361536
{
15371537
response->part = P_DONE;
1538-
if (response->buflen != response->len)
1538+
if (response->buflen != response->len && response->len > 0)
15391539
{
15401540
char *tmp = (char*)realloc(response->data, response->len);
15411541
if (!tmp)

0 commit comments

Comments
 (0)