From 9025694d12a5f259c7cff13074bd7c67804abd65 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Wed, 17 Oct 2018 20:22:17 +0200 Subject: [PATCH] Parser: free old string in utf8_string The utf8_string() function is used to extract whitespace-trimmed strings. The function would happily overwrite the pointer to the old string, which could therefore leak (suppose an XML has redundant attributes). Therefore preemtively free the string output parameter. This makes it of course necessary to only pass in NULL-initialized pointers or pointers to owned string. The code survives the current set of parser-tests. Signed-off-by: Berthold Stoeger --- core/parse.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/core/parse.c b/core/parse.c index 76b66733f..005a971e5 100644 --- a/core/parse.c +++ b/core/parse.c @@ -394,10 +394,16 @@ void userid_stop(void) in_userid = false; } +/* + * Copy whitespace-trimmed string. Warning: the passed in string will be freed, + * therefore make sure to only pass in to NULL-initialized pointers or pointers + * to owned strings + */ void utf8_string(char *buffer, void *_res) { char **res = _res; int size; + free(*res); size = trimspace(buffer); if(size) *res = strdup(buffer);