mirror of
https://github.com/envmodules/modules.git
synced 2026-06-10 00:56:30 +08:00
sysconf may fail to obtain the value of the NGROUPS_MAX variable. In
such case, it returns -1 and sets errno to indicate the error.
Let's handle this situation as the size argument of ckalloc is an
unsigned int so the size of the allocated memory would be UINT_MAX instead.
Subsequently, getgroups would fail with EINVAL as maxgroupsize is non-zero
but less than the number of GIDs that would have been returned.
Note that if sysconf returns -1 and leaves errno intact, the given
variable has no limit. However, that does not seem to be the case on
any reasonable operating system [1].
Found by Coverity.
Resolves:
modules-5.0.1/lib/envmodules.c:355: negative_return_fn: Function "sysconf(_SC_NGROUPS_MAX)" returns a negative number.
modules-5.0.1/lib/envmodules.c:355: assign: Assigning: "maxgroups" = "sysconf(_SC_NGROUPS_MAX)".
modules-5.0.1/lib/envmodules.c:368: negative_returns: "maxgroups" is passed to a parameter that cannot be negative.
366|
367| #if defined (HAVE_GETGROUPS)
368|-> if ((ngroups = getgroups(maxgroups, groups)) == -1) {
369| Tcl_SetErrno(errno);
370| Tcl_SetObjResult(interp,
[1] https://www.j3e.de/ngroups.html
17 KiB
17 KiB