]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
useradd: Check sysconf return value
authorTobias Stoeckmann <tobias@stoeckmann.org>
Wed, 11 Mar 2026 21:34:05 +0000 (22:34 +0100)
committerAlejandro Colomar <foss+github@alejandro-colomar.es>
Fri, 13 Mar 2026 20:15:39 +0000 (21:15 +0100)
Verify that sysconf does not return -1. It is not important if it's due
to an error or due to a missing upper boundary. In both cases, fall back
to a constant value.

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

index 6570cee830269c9e79fc2e0b7052ee36fab2467f..5534e1d860ff5658d08f823a8e5ea8409714980d 100644 (file)
@@ -221,6 +221,10 @@ static bool home_added = false;
 #define DBTRFS_SUBVOLUME_HOME  "BTRFS_SUBVOLUME_HOME"
 #define DLOG_INIT              "LOG_INIT"
 
+#ifndef NGROUPS_MAX
+#define NGROUPS_MAX            65536
+#endif
+
 /* local function prototypes */
 NORETURN static void fail_exit (int, bool);
 static void get_defaults(const struct option_flags *);
@@ -2529,6 +2533,8 @@ int main (int argc, char **argv)
 #endif
 
        sys_ngroups = sysconf (_SC_NGROUPS_MAX);
+       if (sys_ngroups == -1)
+               sys_ngroups = NGROUPS_MAX;
        user_groups = xmalloc_T(1 + sys_ngroups, char *);
        /*
         * Initialize the list to be empty