From: Alejandro Colomar Date: Fri, 17 May 2024 11:10:46 +0000 (+0200) Subject: src/useradd.c: set_defaults(): Do not free(3) the result of asprintf(3) if it failed X-Git-Tag: 4.15.2~29 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=701fe4cf1aeac9e66fa949369c91d135dbf375d2;p=thirdparty%2Fshadow.git src/useradd.c: set_defaults(): Do not free(3) the result of asprintf(3) if it failed See asprintf(3): RETURN VALUE When successful, these functions return the number of bytes printed, just like sprintf(3). If memory allocation wasn’t possi‐ ble, or some other error occurs, these functions will return -1, and the contents of strp are undefined. Reviewed-by: Iker Pedrosa Signed-off-by: Alejandro Colomar --- diff --git a/src/useradd.c b/src/useradd.c index bc72e6bca..6a3edfe3b 100644 --- a/src/useradd.c +++ b/src/useradd.c @@ -558,7 +558,7 @@ static int set_defaults (void) fprintf(stderr, _("%s: cannot create new defaults file: %s\n"), Prog, strerror(errno)); - goto err_free_def; + goto err_free_new; } } @@ -749,6 +749,7 @@ static int set_defaults (void) err_free_def: if (prefix[0]) free(default_file); +err_free_new: free(new_file); return ret;