From: Alejandro Colomar Date: Sun, 30 Jul 2023 12:03:07 +0000 (+0200) Subject: Use MEMZERO() instead of its pattern X-Git-Tag: 4.15.0-rc1~205 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f3ee47fe3f538c72e9d4b4f2c167d102110a1672;p=thirdparty%2Fshadow.git Use MEMZERO() instead of its pattern This patch implicitly adds the safety of SIZEOF_ARRAY(), since the calls were using sizeof() instead. Cc: Christian Göttsche Cc: Serge Hallyn Cc: Iker Pedrosa Signed-off-by: Alejandro Colomar --- diff --git a/lib/limits.c b/lib/limits.c index 96998e9e8..1916f3452 100644 --- a/lib/limits.c +++ b/lib/limits.c @@ -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: diff --git a/lib/loginprompt.c b/lib/loginprompt.c index bf8c3cdda..e2bef7ab0 100644 --- a/lib/loginprompt.c +++ b/lib/loginprompt.c @@ -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); } diff --git a/src/gpasswd.c b/src/gpasswd.c index 853cb03ae..12fbc8072 100644 --- a/src/gpasswd.c +++ b/src/gpasswd.c @@ -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; diff --git a/src/passwd.c b/src/passwd.c index a89790db6..673282cfb 100644 --- a/src/passwd.c +++ b/src/passwd.c @@ -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, diff --git a/src/sulogin.c b/src/sulogin.c index 14bec6ae7..7f2d86955 100644 --- a/src/sulogin.c +++ b/src/sulogin.c @@ -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 */