]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
src/sulogin.c: Simplify password handling
authorSamanta Navarro <ferivoz@riseup.net>
Fri, 19 Jan 2024 11:54:14 +0000 (11:54 +0000)
committerAlejandro Colomar <alx@kernel.org>
Thu, 1 Feb 2024 13:37:00 +0000 (14:37 +0100)
The password returned by agetpass can be used directly without copying
it into a char array first.

Reviewed-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
src/sulogin.c

index 440c7e0ce3fb702b45a2a772d862e063f05adc54..4b141465752fade342fa988a4e1f8fdced77bdea 100644 (file)
 #include "attr.h"
 #include "defines.h"
 #include "getdef.h"
-#include "memzero.h"
 #include "prototypes.h"
 #include "pwauth.h"
 /*@-exitarg@*/
 #include "exitcodes.h"
 #include "shadowlog.h"
-#include "string/strtcpy.h"
 
 
 /*
@@ -60,7 +58,6 @@ static void catch_signals (MAYBE_UNUSED int sig)
 main(int argc, char **argv)
 {
        int            err = 0;
-       char           pass[BUFSIZ];
        char           **envp = environ;
        TERMIO         termio;
        struct passwd  pwent = {};
@@ -135,7 +132,7 @@ main(int argc, char **argv)
        (void) alarm (ALARM);           /* only wait so long ... */
 
        do {                    /* repeatedly get login/password pairs */
-               char *cp;
+               char *pass;
                if (pw_entry("root", &pwent) == -1) {   /* get entry from password file */
                        /*
                         * Fail secure
@@ -150,7 +147,7 @@ main(int argc, char **argv)
                 */
 
                /* get a password for root */
-               cp = agetpass (_(
+               pass = agetpass (_(
 "\n"
 "Type control-d to proceed with normal startup,\n"
 "(or give root password for system maintenance):"));
@@ -160,25 +157,24 @@ main(int argc, char **argv)
                 * it will work with standard getpass() (no NULL on EOF).
                 * --marekm
                 */
-               if ((NULL == cp) || ('\0' == *cp)) {
-                       erase_pass (cp);
+               if ((NULL == pass) || ('\0' == *pass)) {
+                       erase_pass (pass);
                        (void) puts ("");
 #ifdef TELINIT
                        execl (PATH_TELINIT, "telinit", RUNLEVEL, (char *) NULL);
 #endif
                        exit (0);
                }
-               STRTCPY(pass, cp);
-               erase_pass (cp);
 
                done = valid(pass, &pwent);
+               erase_pass (pass);
+
                if (!done) {    /* check encrypted passwords ... */
                        /* ... encrypted passwords did not match */
                        sleep (2);
                        (void) puts (_("Login incorrect"));
                }
        } while (!done);
-       MEMZERO(pass);
        (void) alarm (0);
        (void) signal (SIGALRM, SIG_DFL);
        environ = newenvp;      /* make new environment active */