From a87afab391b309692ac30bed8eecbdbcdc5fd96f Mon Sep 17 00:00:00 2001 From: 1820893135-pixel <1820893135-pixel@users.noreply.github.com> Date: Sat, 12 Sep 2026 18:12:50 +0800 Subject: [PATCH] load_ini_buffer: allocate ini_length + 1 bytes `strip_ini_cache()` documents that the `ini_source` buffer must be able to hold `ini_length + 1` bytes, since the first thing it does is ini_source[ini_length] = '\0'; regardless of the input. The bundled `load_ini_buffer()` helper allocated only `ini_length` bytes and then handed the buffer to `strip_ini_cache()`, so every non-empty input wrote one byte past the allocation (an ASan heap-buffer-overflow on the NUL terminator). Allocate `ini_length + 1` bytes to match the documented contract. Reproducer (ASan): calling `load_ini_buffer("[S]\nkey = value\n", ...)` aborts with "heap-buffer-overflow ... WRITE of size 1 ... in strip_ini_cache" before the fix and runs cleanly afterwards. Fixes #20. --- examples/utilities/load_ini_buffer.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/examples/utilities/load_ini_buffer.h b/examples/utilities/load_ini_buffer.h index 1620b3a..e5aae88 100644 --- a/examples/utilities/load_ini_buffer.h +++ b/examples/utilities/load_ini_buffer.h @@ -30,7 +30,10 @@ int load_ini_buffer ( void * const user_data ) { - char * const ini_cache = malloc(ini_length); + /* `strip_ini_cache()` documents that it will immediately write a NUL + terminator at `ini_source[ini_length]`, so the buffer must be able to + hold `ini_length + 1` bytes. */ + char * const ini_cache = malloc(ini_length + 1); if (!ini_cache) {