From 92b037e9765e069afe5e4cbe6bdf9cd19e928dda Mon Sep 17 00:00:00 2001 From: Valerio Santinelli Date: Fri, 8 Sep 2023 15:40:29 +0200 Subject: [PATCH] Fixed a buffer overflow issue with http calls and emscripten --- src/binocle/core/binocle_http.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/binocle/core/binocle_http.c b/src/binocle/core/binocle_http.c index 9a1a6a3f..7ee6535f 100644 --- a/src/binocle/core/binocle_http.c +++ b/src/binocle/core/binocle_http.c @@ -31,9 +31,10 @@ bool binocle_http_get(const char *url, binocle_http_body_t *body) { body->memory = malloc(1); /* will be grown as needed by the realloc above */ body->size = 0; /* no data at this point */ char *res = do_binocle_http_get(url); - body->memory = SDL_realloc(body->memory, SDL_strlen(res)); - body->size = SDL_strlen(res); + body->memory = SDL_realloc(body->memory, SDL_strlen(res) + 1); + body->size = SDL_strlen(res) + 1; SDL_memcpy(body->memory, res, body->size); + body->memory[body->size - 1] = 0; free(res); return 0; }