]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
usermod: Small optimization using memmove for password unlock
authorMartin Kletzander <mkletzan@redhat.com>
Fri, 3 Mar 2023 10:57:23 +0000 (11:57 +0100)
committerSerge Hallyn <serge@hallyn.com>
Fri, 26 May 2023 20:14:02 +0000 (15:14 -0500)
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
src/usermod.c

index 87c93d93c48bb6955ca90aa0190ca58ffe983fcd..77d4ef49193e2c52977b7e76c15610390925f4f5 100644 (file)
@@ -430,8 +430,6 @@ static char *new_pw_passwd (char *pw_pass)
                strcat (buf, pw_pass);
                pw_pass = buf;
        } else if (Uflg && pw_pass[0] == '!') {
-               char *s;
-
                if (pw_pass[1] == '\0') {
                        fprintf (stderr,
                                 _("%s: unlocking the user's password would result in a passwordless account.\n"
@@ -445,11 +443,7 @@ static char *new_pw_passwd (char *pw_pass)
                              "updating password", user_newname, user_newid, 0);
 #endif
                SYSLOG ((LOG_INFO, "unlock user '%s' password", user_newname));
-               s = pw_pass;
-               while ('\0' != *s) {
-                       *s = *(s + 1);
-                       s++;
-               }
+               memmove(pw_pass, pw_pass + 1, strlen(pw_pass));
        } else if (pflg) {
 #ifdef WITH_AUDIT
                audit_logger (AUDIT_USER_CHAUTHTOK, Prog,