From 480682e6423308df28fed2c33770a9c400db6806 Mon Sep 17 00:00:00 2001 From: Maks Mishin Date: Tue, 10 Dec 2024 12:26:32 +0300 Subject: [PATCH] sys-utils: (setpriv): fix potential memory leak 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 --- sys-utils/setpriv.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sys-utils/setpriv.c b/sys-utils/setpriv.c index 19b8c80aa..87299a10d 100644 --- a/sys-utils/setpriv.c +++ b/sys-utils/setpriv.c @@ -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) -- 2.47.3