From a63f061bc42d7c472ba72a5e3feacc0751d4d072 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Mario=20Spei=C3=9F?= <1034-135@online.de> Date: Fri, 18 Jan 2013 23:52:36 +0100 Subject: [PATCH] ConfigLoadString loses the last character of strings MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit ConfigLoadString allocates memory for 'size' bytes and copys a NULL terminated string to this buffer. ConfigSaveString instead expects the buffer to be NULL terminated but: - the 'size' saved to the cache is the char count - the string is written without terminating NULL. So obviously ConfigLoadString does not match the behaviour of ConfigSaveString. It seems to me that the cached module configuration is not working at all due to comparing the module file names within CacheFind - this should never have found a match. I think this would need some more testing. Regards, Mario Signed-off-by: Rémi Denis-Courmont --- src/modules/cache.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/cache.c b/src/modules/cache.c index bd9b32d202..9d83632ddb 100644 --- a/src/modules/cache.c +++ b/src/modules/cache.c @@ -96,7 +96,7 @@ error: if (size > 0) { - psz = malloc (size); + psz = malloc (size+1); if (unlikely(psz == NULL)) goto error; if (fread (psz, 1, size, file) != size) @@ -104,7 +104,7 @@ error: free (psz); goto error; } - psz[size - 1] = '\0'; + psz[size] = '\0'; } *p = psz; return 0; -- 2.39.2