]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
sys-utils: (setpriv): fix potential memory leak
authorMaks Mishin <maks.mishinFZ@gmail.com>
Tue, 10 Dec 2024 09:26:32 +0000 (12:26 +0300)
committerMaks Mishin <maks.mishinFZ@gmail.com>
Tue, 10 Dec 2024 09:35:23 +0000 (12:35 +0300)
Dynamic memory, referenced by 'my_caps' is allocated by calling function 'xstrdup'
add then changed by calling of strsep function.
The free(my_caps) call is incorrect if my_caps != NULL, and points to some
place inside or outside the source string.

Signed-off-by: Maks Mishin <maks.mishinFZ@gmail.com>
sys-utils/setpriv.c

index 19b8c80aa797cb3edacbf90b638e0e14c02409f6..87299a10d124687168ad1a5c56d3823aa7850732 100644 (file)
@@ -542,6 +542,7 @@ static int cap_update(capng_act_t action,
 static void do_caps(enum cap_type type, const char *caps)
 {
        char *my_caps = xstrdup(caps);
+       char *source_my_caps = my_caps;
        char *c;
 
        while ((c = strsep(&my_caps, ","))) {
@@ -572,7 +573,7 @@ static void do_caps(enum cap_type type, const char *caps)
                }
        }
 
-       free(my_caps);
+       free(source_my_caps);
 }
 
 static void parse_securebits(struct privctx *opts, const char *arg)