From: Tobias Stoeckmann Date: Tue, 23 Dec 2025 11:32:02 +0000 (+0100) Subject: chage: Remove unneeded xstrdup calls X-Git-Tag: 4.19.0~18 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cf90975d11e3de30faa929c4be225ce97acb58f4;p=thirdparty%2Fshadow.git chage: Remove unneeded xstrdup calls Duplicating name and hash is not needed here, because duplication occurs in spw_update. You can detect the small memory leak with tools like valgrind. More importantly though, if xstrdup fails, it calls exit. The update_age function is in the "criticial section" between open_files and close_files, though. Correct error handling would require fail_exit to release the held locks. Signed-off-by: Tobias Stoeckmann --- diff --git a/src/chage.c b/src/chage.c index 419c17233..fffd22b99 100644 --- a/src/chage.c +++ b/src/chage.c @@ -32,7 +32,6 @@ #include "string/sprintf/snprintf.h" #include "string/strcmp/streq.h" #include "string/strcpy/strtcpy.h" -#include "string/strdup/strdup.h" #include "string/strerrno.h" #include "string/strftime.h" #include "time/day_to_str.h" @@ -613,8 +612,8 @@ static void update_age (/*@null@*/const struct spwd *sp, struct passwd pwent = *pw; memzero(&spwent, sizeof(spwent)); - spwent.sp_namp = xstrdup (pwent.pw_name); - spwent.sp_pwdp = xstrdup (pwent.pw_passwd); + spwent.sp_namp = pwent.pw_name; + spwent.sp_pwdp = pwent.pw_passwd; spwent.sp_flag = SHADOW_SP_FLAG_UNSET; pwent.pw_passwd = SHADOW_PASSWD_STRING; /* XXX warning: const */ @@ -624,8 +623,8 @@ static void update_age (/*@null@*/const struct spwd *sp, fail_exit (E_NOPERM, process_selinux); } } else { - spwent.sp_namp = xstrdup (sp->sp_namp); - spwent.sp_pwdp = xstrdup (sp->sp_pwdp); + spwent.sp_namp = sp->sp_namp; + spwent.sp_pwdp = sp->sp_pwdp; spwent.sp_flag = sp->sp_flag; }