]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
chfn: Replace STRFCPY() by STRLCPY()
authorAlejandro Colomar <alx@kernel.org>
Thu, 8 Jun 2023 18:39:04 +0000 (20:39 +0200)
committerIker Pedrosa <ikerpedrosam@gmail.com>
Fri, 1 Sep 2023 07:39:23 +0000 (09:39 +0200)
The variables are only being read as strings (char *), so data after the
'\0' can't be leaked.

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>
src/chfn.c

index 5018ab87f312dcb01f7e39335ccabd36a2021e16..242868f47ebf8909b882459652f3214c8563c2a6 100644 (file)
@@ -32,6 +32,7 @@
 /*@-exitarg@*/
 #include "exitcodes.h"
 #include "shadowlog.h"
+#include "strlcpy.h"
 
 /*
  * Global variables.
@@ -275,7 +276,7 @@ static void process_flags (int argc, char **argv)
                                exit (E_NOPERM);
                        }
                        fflg = true;
-                       STRFCPY (fullnm, optarg);
+                       STRLCPY(fullnm, optarg);
                        break;
                case 'h':
                        if (!may_change_field ('h')) {
@@ -284,7 +285,7 @@ static void process_flags (int argc, char **argv)
                                exit (E_NOPERM);
                        }
                        hflg = true;
-                       STRFCPY (homeph, optarg);
+                       STRLCPY(homeph, optarg);
                        break;
                case 'o':
                        if (!amroot) {
@@ -298,7 +299,7 @@ static void process_flags (int argc, char **argv)
                                         _("%s: fields too long\n"), Prog);
                                exit (E_NOPERM);
                        }
-                       STRFCPY (slop, optarg);
+                       STRLCPY(slop, optarg);
                        break;
                case 'r':
                        if (!may_change_field ('r')) {
@@ -307,7 +308,7 @@ static void process_flags (int argc, char **argv)
                                exit (E_NOPERM);
                        }
                        rflg = true;
-                       STRFCPY (roomno, optarg);
+                       STRLCPY(roomno, optarg);
                        break;
                case 'R': /* no-op, handled in process_root_flag () */
                        break;
@@ -321,7 +322,7 @@ static void process_flags (int argc, char **argv)
                                exit (E_NOPERM);
                        }
                        wflg = true;
-                       STRFCPY (workph, optarg);
+                       STRLCPY(workph, optarg);
                        break;
                default:
                        usage (E_USAGE);
@@ -508,7 +509,8 @@ static void get_old_fields (const char *gecos)
 {
        char *cp;               /* temporary character pointer       */
        char old_gecos[BUFSIZ]; /* buffer for old GECOS fields       */
-       STRFCPY (old_gecos, gecos);
+
+       STRLCPY(old_gecos, gecos);
 
        /*
         * Now get the full name. It is the first comma separated field in