Files
modules/lib/envmodules.c
Lukáš Zaoral 14eabbd047 lib: handle sysconf failure in InitStateUsergroupsObjCmd
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
2022-03-31 13:06:26 +02:00

17 KiB