From 1ac759a9f9650fd961f366ef646a757d5119e8e4 Mon Sep 17 00:00:00 2001 From: Federico Angelilli Date: Wed, 10 Jul 2024 23:44:45 +0200 Subject: Fix buffer overflow --- any_ini.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/any_ini.h b/any_ini.h index f05b579..9d9afe6 100644 --- a/any_ini.h +++ b/any_ini.h @@ -424,7 +424,10 @@ static char *any_ini_stream_until(any_ini_stream_t *ini, size_t start, char c) // Copy current buffer and refill case '\0': tmp = ANY_INI_REALLOC(value, size + ini->cursor - start); - if (!tmp) return value; + if (!tmp) { + value[size - 1] = 0; + return value; + } size += any_ini_copy(tmp + size, ini->buffer + start, ini->cursor - start); value = tmp; @@ -469,8 +472,11 @@ static char *any_ini_stream_until(any_ini_stream_t *ini, size_t start, char c) } } - tmp = ANY_INI_REALLOC(value, size + ini->cursor - start); - if (!tmp) return value; + tmp = ANY_INI_REALLOC(value, size + ini->cursor - start + 1); + if (!tmp) { + value[size - 1] = 0; + return value; + } size += any_ini_copy(tmp + size, ini->buffer + start, ini->cursor - start); size = any_ini_trim(tmp, 0, size); -- cgit v1.2.3