]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
chage: Remove unneeded xstrdup calls
authorTobias Stoeckmann <tobias@stoeckmann.org>
Tue, 23 Dec 2025 11:32:02 +0000 (12:32 +0100)
committerAlejandro Colomar <foss+github@alejandro-colomar.es>
Tue, 23 Dec 2025 21:45:19 +0000 (22:45 +0100)
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 <tobias@stoeckmann.org>
src/chage.c

index 419c172337591b65bc9c983741fbbd5569c610e9..fffd22b9941e7f4fa8a992960cbd517bc29b905e 100644 (file)
@@ -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;
        }