]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
Use STRLCPY() instead of its pattern
authorAlejandro Colomar <alx@kernel.org>
Sat, 29 Jul 2023 16:22:12 +0000 (18:22 +0200)
committerIker Pedrosa <ikerpedrosam@gmail.com>
Fri, 1 Sep 2023 07:39:23 +0000 (09:39 +0200)
This makes it harder to make mistakes while editing the code.  Since the
sizeof's can be autocalculated, let the machine do that.  It also
reduces the cognitive load while reading the code.

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/console.c
lib/utmp.c
src/login.c
src/su.c

index 7e2132dd7bfca2b62de75ee28e33cc60e9bc142d..a847720a4882b8c680f600356c8761d7f97266ea 100644 (file)
@@ -13,6 +13,7 @@
 #include <stdio.h>
 #include "getdef.h"
 #include "prototypes.h"
+#include "strlcpy.h"
 
 #ident "$Id$"
 
@@ -44,7 +45,7 @@ static bool is_listed (const char *cfgin, const char *tty, bool def)
 
        if (*cons != '/') {
                char *pbuf;
-               strlcpy (buf, cons, sizeof (buf));
+               STRLCPY(buf, cons);
                pbuf = &buf[0];
                while ((s = strtok (pbuf, ":")) != NULL) {
                        if (strcmp (s, tty) == 0) {
index aa837ffb56c2fd1e2e3cf5837866af75b0126495..9b173327ac7ad90e9c77bd2c3997402eb19a4f7d 100644 (file)
@@ -24,6 +24,7 @@
 
 #include "alloc.h"
 #include "sizeof.h"
+#include "strlcpy.h"
 #include "zustr2stp.h"
 
 #ident "$Id$"
@@ -46,7 +47,7 @@ static bool is_my_tty (const char tty[UT_LINESIZE])
        if ('\0' == tmptty[0]) {
                const char *tname = ttyname (STDIN_FILENO);
                if (NULL != tname)
-                       (void) strlcpy (tmptty, tname, sizeof(tmptty));
+                       STRLCPY(tmptty, tname);
        }
 
        if ('\0' == tmptty[0]) {
index 9faec81899f91402f8c701038d0ba78c8345c564..93fd248c1f48a64ee482eae47f22b978e9bd589a 100644 (file)
@@ -711,8 +711,7 @@ int main (int argc, char **argv)
                                  sizeof (loginprompt),
                                  _("%s login: "), hostn);
                } else {
-                       strlcpy (loginprompt, _("login: "),
-                                sizeof (loginprompt));
+                       STRLCPY(loginprompt, _("login: "));
                }
 
                retcode = pam_set_item (pamh, PAM_USER_PROMPT, loginprompt);
index e3ede542409d48f16364f92255c66ed7a07644ec..9c577f35a015c790fe42becb3ff3e1e9a2235a70 100644 (file)
--- a/src/su.c
+++ b/src/su.c
@@ -676,7 +676,7 @@ static /*@only@*/struct passwd * do_check_perms (void)
                SYSLOG ((LOG_INFO,
                         "Change user from '%s' to '%s' as requested by PAM",
                         name, tmp_name));
-               if (strlcpy (name, tmp_name, sizeof(name)) >= sizeof(name)) {
+               if (STRLCPY(name, tmp_name) == -1) {
                        fprintf (stderr, _("Overlong user name '%s'\n"),
                                 tmp_name);
                        SYSLOG ((LOG_NOTICE, "Overlong user name '%s'",