1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

Use dynamic maximum configuration values when necessary (#370)

This commit fixes an issue with how ksh was obtaining the value of
NGROUPS_MAX. On some systems this setting can be changed (e.g., on
illumos adding 'set ngroups_max=32' to /etc/system then rebooting
changes NGROUPS_MAX from 16 to 32). Ksh was using NGROUPS_MAX with
the assumption it's a static value, which could cause issues on
systems where it isn't static. This bugfix is inspired by the one
from <b1362c3a5>, although it
has been expanded a bit to account for OPEN_MAX as well.

src/cmd/ksh93/sh/init.c, src/lib/libcmd/fds.c:
- Rename the getconf() macro to astconf_long() and move it to ast.h
  to prevent redundancy. Other sections of the code have been
  modified to use this macro for astconf() to account for
  dynamic settings.
- An equivalent macro for unsigned long values (astconf_ulong) has
  been added.
- Prefer sysconf(3) where available. It has better performance as it
  returns a numeric value directly instead of via string
  conversion.
- The astconf_long and astconf_ulong macros have been documented in
  the ast(3) man page.
This commit is contained in:
Johnothan King 2021-12-12 22:51:59 -08:00 committed by Martijn Dekker
parent fc752b574a
commit c2ac69b2d5
15 changed files with 81 additions and 27 deletions

View file

@ -666,7 +666,7 @@ skip:
if((maxgroups=getgroups(0,(gid_t*)0)) <= 0)
{
/* pre-POSIX system */
maxgroups=NGROUPS_MAX;
maxgroups = (int)astconf_long(CONF_NGROUPS_MAX);
}
}
groups = (gid_t*)stakalloc((maxgroups+1)*sizeof(gid_t));
@ -680,7 +680,7 @@ skip:
}
}
}
# endif /* _lib_getgroups */
#endif /* _lib_getgroups */
if(statb.st_mode & mode)
return(0);
}

View file

@ -46,7 +46,7 @@ tst note{ determining extra bytes per argument for arguments list }end output{
for(i=0; environ[i]; i++)
envlen += strlen(environ[i]) + 1 + extra_bytes;
envlen += 1 + extra_bytes; /* final null element */
argmax = strtoimax(astconf("ARG_MAX",NiL,NiL),NiL,0) - envlen;
argmax = (int)astconf_long(CONF_ARG_MAX) - envlen;
if (argmax < 2048)
{
error(ERROR_ERROR|2, "argmax too small");

View file

@ -144,9 +144,6 @@ char e_version[] = "\n@(#)$Id: Version "
extern char **environ;
#endif
#undef getconf
#define getconf(x) strtol(astconf(x,NiL,NiL),NiL,0)
struct seconds
{
Namfun_t hdr;
@ -1223,9 +1220,9 @@ Shell_t *sh_init(register int argc,register char *argv[], Shinit_f userinit)
shgd->euserid=geteuid();
shgd->groupid=getgid();
shgd->egroupid=getegid();
shgd->lim.clk_tck = getconf("CLK_TCK");
shgd->lim.arg_max = getconf("ARG_MAX");
shgd->lim.child_max = getconf("CHILD_MAX");
shgd->lim.arg_max = astconf_long(CONF_ARG_MAX);
shgd->lim.child_max = (int)astconf_long(CONF_CHILD_MAX);
shgd->lim.clk_tck = (int)astconf_long(CONF_CLK_TCK);
if(shgd->lim.arg_max <=0)
shgd->lim.arg_max = ARG_MAX;
if(shgd->lim.child_max <=0)

View file

@ -403,7 +403,7 @@ int sh_iovalidfd(Shell_t *shp, int fd)
return(0);
if(fd < shp->gd->lim.open_max)
return(1);
max = strtol(astconf("OPEN_MAX",NiL,NiL),NiL,0);
max = (int)astconf_long(CONF_OPEN_MAX);
if(fd >= max)
{
errno = EBADF;

View file

@ -329,7 +329,7 @@ int eaccess(register const char *name, register int mode)
if((maxgroups=getgroups(0,groups)) < 0)
{
/* pre-POSIX system */
maxgroups=NGROUPS_MAX;
maxgroups = (int)astconf_long(CONF_NGROUPS_MAX);
}
}
groups = (gid_t*)malloc((maxgroups+1)*sizeof(gid_t));