Skip to content

Commit

Permalink
src/newusers.c: Turn nusers into size_t
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
stoeckmann authored and alejandro-colomar committed Jan 15, 2025
1 parent 4c7aa8c commit 950cd40
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/newusers.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <getopt.h>
#include <ctype.h>
#include <errno.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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"),
Expand Down

0 comments on commit 950cd40

Please sign in to comment.