]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
Use MEMZERO() instead of its pattern
authorAlejandro Colomar <alx@kernel.org>
Sun, 30 Jul 2023 12:03:07 +0000 (14:03 +0200)
committerIker Pedrosa <ikerpedrosam@gmail.com>
Fri, 1 Sep 2023 07:39:23 +0000 (09:39 +0200)
This patch implicitly adds the safety of SIZEOF_ARRAY(), since the calls
were using sizeof() instead.

Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/limits.c
lib/loginprompt.c
src/gpasswd.c
src/passwd.c
src/sulogin.c

index 96998e9e813f641a84036089be6a70381c130e58..1916f3452c11d3fa89bf01ae70ec2f6ea14c1e71 100644 (file)
@@ -357,11 +357,11 @@ static int setup_user_limits (const char *uname)
        char tempbuf[1024];
 
        /* init things */
-       memzero (buf, sizeof (buf));
-       memzero (name, sizeof (name));
-       memzero (limits, sizeof (limits));
-       memzero (deflimits, sizeof (deflimits));
-       memzero (tempbuf, sizeof (tempbuf));
+       MEMZERO(buf);
+       MEMZERO(name);
+       MEMZERO(limits);
+       MEMZERO(deflimits);
+       MEMZERO(tempbuf);
 
        /* start the checks */
        fil = fopen (LIMITS_FILE, "r");
@@ -378,7 +378,7 @@ static int setup_user_limits (const char *uname)
                if (('#' == buf[0]) || ('\n' == buf[0])) {
                        continue;
                }
-               memzero (tempbuf, sizeof (tempbuf));
+               MEMZERO(tempbuf);
                /* a valid line should have a username, then spaces,
                 * then limits
                 * we allow the format:
index bf8c3cdda706eb9d2fa39425a2c785a6c6d95746..e2bef7ab0d762fa6dc8dbed481507304e96756e9 100644 (file)
@@ -80,7 +80,7 @@ void login_prompt (char *name, int namesize)
         * removed.
         */
 
-       memzero (buf, sizeof buf);
+       MEMZERO(buf);
        if (fgets (buf, sizeof buf, stdin) != buf) {
                exit (EXIT_FAILURE);
        }
index 853cb03ae2953e6fabcfc8930aee8f184e6b2de7..12fbc8072eb633a99b14ef5461fb9a26e81cec81 100644 (file)
@@ -899,7 +899,7 @@ static void change_passwd (struct group *gr)
                erase_pass (cp);
                cp = agetpass (_("Re-enter new password: "));
                if (NULL == cp) {
-                       memzero (pass, sizeof pass);
+                       MEMZERO(pass);
                        exit (1);
                }
 
@@ -909,7 +909,7 @@ static void change_passwd (struct group *gr)
                }
 
                erase_pass (cp);
-               memzero (pass, sizeof pass);
+               MEMZERO(pass);
 
                if (retries + 1 < RETRIES) {
                        puts (_("They don't match; try again"));
@@ -929,7 +929,7 @@ static void change_passwd (struct group *gr)
                         Prog, salt, strerror (errno));
                exit (1);
        }
-       memzero (pass, sizeof pass);
+       MEMZERO(pass);
 #ifdef SHADOWGRP
        if (is_shadowgrp) {
                gr->gr_passwd = SHADOW_PASSWD_STRING;
index a89790db6157b7fc1c3fb11cfae35b13abd5371e..673282cfbb95d19f09080b2f94d009d5389464fc 100644 (file)
@@ -294,8 +294,8 @@ static int new_password (const struct passwd *pw)
        for (i = getdef_num ("PASS_CHANGE_TRIES", 5); i > 0; i--) {
                cp = agetpass (_("New password: "));
                if (NULL == cp) {
-                       memzero (orig, sizeof orig);
-                       memzero (pass, sizeof pass);
+                       MEMZERO(orig);
+                       MEMZERO(pass);
                        return -1;
                }
                if (warned && (strcmp (pass, cp) != 0)) {
@@ -322,8 +322,8 @@ static int new_password (const struct passwd *pw)
                }
                cp = agetpass (_("Re-enter new password: "));
                if (NULL == cp) {
-                       memzero (orig, sizeof orig);
-                       memzero (pass, sizeof pass);
+                       MEMZERO(orig);
+                       MEMZERO(pass);
                        return -1;
                }
                if (strcmp (cp, pass) != 0) {
@@ -334,10 +334,10 @@ static int new_password (const struct passwd *pw)
                        break;
                }
        }
-       memzero (orig, sizeof orig);
+       MEMZERO(orig);
 
        if (i == 0) {
-               memzero (pass, sizeof pass);
+               MEMZERO(pass);
                return -1;
        }
 
@@ -346,7 +346,7 @@ static int new_password (const struct passwd *pw)
         */
        salt = crypt_make_salt (NULL, NULL);
        cp = pw_encrypt (pass, salt);
-       memzero (pass, sizeof pass);
+       MEMZERO(pass);
 
        if (NULL == cp) {
                fprintf (stderr,
index 14bec6ae71b63d7bb3a86f5a49795b4e329f31ce..7f2d869557fa29208d51fccd61753f76d6514006 100644 (file)
@@ -167,7 +167,7 @@ static void catch_signals (unused int sig)
                sleep (2);
                (void) puts (_("Login incorrect"));
        }
-       memzero (pass, sizeof pass);
+       MEMZERO(pass);
        (void) alarm (0);
        (void) signal (SIGALRM, SIG_DFL);
        environ = newenvp;      /* make new environment active */