diff options
| author | Federico Angelilli <code@fedang.net> | 2024-07-10 23:44:45 +0200 |
|---|---|---|
| committer | Federico Angelilli <code@fedang.net> | 2024-07-10 23:44:45 +0200 |
| commit | 1ac759a9f9650fd961f366ef646a757d5119e8e4 (patch) | |
| tree | 40f4d7e24dcf7420b4b69e08b59e1fd08df4e23e | |
| parent | d321f9b35e4fc752f8b28346b7e489e6df7c8e10 (diff) | |
Fix buffer overflow
| -rw-r--r-- | any_ini.h | 12 |
1 files changed, 9 insertions, 3 deletions
@@ -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); |
