]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libblkid: fix memory leak in config parser
authorSamanta Navarro <ferivoz@riseup.net>
Sun, 8 Nov 2020 11:44:55 +0000 (11:44 +0000)
committerKarel Zak <kzak@redhat.com>
Fri, 13 Nov 2020 11:35:50 +0000 (12:35 +0100)
Multiple occurrences of CACHE_FILE lead to memory leaks.
Also if last occurrence of CACHE_FILE is empty then cache file is not
set to NULL again.

An example /etc/blkid.conf could be:

CACHE_FILE=/tmp/cache1
CACHE_FILE=/tmp/cache2
CACHE_FILE=

I would expect that CACHE_FILE is empty but actually it is still
/tmp/cache2.

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
libblkid/src/config.c

index 52f159d870668116e5066f62fa059f567f5cf564..f229b3e63247a046c65de71908997c56bcd8d43b 100644 (file)
@@ -95,8 +95,11 @@ static int parse_next(FILE *fd, struct blkid_config *conf)
                        conf->uevent = FALSE;
        } else if (!strncmp(s, "CACHE_FILE=", 11)) {
                s += 11;
+               free(conf->cachefile);
                if (*s)
                        conf->cachefile = strdup(s);
+               else
+                       conf->cachefile = NULL;
        } else if (!strncmp(s, "EVALUATE=", 9)) {
                s += 9;
                if (*s && parse_evaluate(conf, s) == -1)