]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
src/newusers.c: Turn nusers into size_t
authorTobias Stoeckmann <tobias@stoeckmann.org>
Sun, 12 Jan 2025 18:21:09 +0000 (19:21 +0100)
committerAlejandro Colomar <alx@kernel.org>
Wed, 15 Jan 2025 23:46:40 +0000 (00:46 +0100)
The nusers variable could, in theory, overflow and trigger an out of
boundary access if a huge amount of entries is added. Realistically,
this is not possible with current systems because way too much data
would be involved.

But let's better be safe than sorry and use correct data types.

Reviewed-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
src/newusers.c

index 2d99ccfe0e5bdfe19d961d350f64ae19653b673e..5fde8bbe3017e6de472c3724e7d6ba365d9d4c43 100644 (file)
@@ -28,6 +28,7 @@
 #include <getopt.h>
 #include <ctype.h>
 #include <errno.h>
+#include <stddef.h>
 #include <stdint.h>
 #include <string.h>
 
@@ -1070,7 +1071,7 @@ int main (int argc, char **argv)
        intmax_t *lines = NULL;
        char **usernames = NULL;
        char **passwords = NULL;
-       unsigned int nusers = 0;
+       size_t nusers = 0;
 #endif                         /* USE_PAM */
 
        log_set_progname(Prog);
@@ -1334,9 +1335,8 @@ int main (int argc, char **argv)
        sssd_flush_cache (SSSD_DB_PASSWD | SSSD_DB_GROUP);
 
 #ifdef USE_PAM
-       unsigned int i;
        /* Now update the passwords using PAM */
-       for (i = 0; i < nusers; i++) {
+       for (size_t i = 0; i < nusers; i++) {
                if (do_pam_passwd_non_interactive ("newusers", usernames[i], passwords[i]) != 0) {
                        fprintf (stderr,
                                 _("%s: (line %jd, user %s) password not changed\n"),