From: Maks Mishin Date: Thu, 10 Oct 2024 17:23:49 +0000 (+0300) Subject: sys-utils: (setpriv): fix potential memory leak X-Git-Tag: v2.42-start~181^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8f15d94a21cbc6886bdf2474e6e1bb507cab1149;p=thirdparty%2Futil-linux.git sys-utils: (setpriv): fix potential memory leak Dynamic memory, referenced by 'buf' is allocated by calling function 'xstrdup' add then changed by calling of strsep function. The free(buf) call is incorrect if buf != NULL, and points to some place inside or outside the source string. --- diff --git a/sys-utils/setpriv.c b/sys-utils/setpriv.c index bd188e4dd..5899552d6 100644 --- a/sys-utils/setpriv.c +++ b/sys-utils/setpriv.c @@ -578,6 +578,7 @@ static void do_caps(enum cap_type type, const char *caps) static void parse_securebits(struct privctx *opts, const char *arg) { char *buf = xstrdup(arg); + char *source_buf = buf; char *c; opts->have_securebits = 1; @@ -631,7 +632,7 @@ static void parse_securebits(struct privctx *opts, const char *arg) opts->securebits |= SECBIT_KEEP_CAPS; /* We need it, and it's reset on exec */ - free(buf); + free(source_buf); } static void do_selinux_label(const char *label)