summaryrefslogtreecommitdiffstats
path: root/usr.sbin/chroot
diff options
context:
space:
mode:
authorbrooks <brooks@FreeBSD.org>2009-06-19 15:58:24 +0000
committerbrooks <brooks@FreeBSD.org>2009-06-19 15:58:24 +0000
commitda4e70cf9ab3e05f67d77de37a7c6c335a5f7e4b (patch)
treeb7d4401847de9bebf98c6fe35d5b61bfd749c7dc /usr.sbin/chroot
parent384550a3864abef16c80a82c2fb12d9726aab2d1 (diff)
downloadFreeBSD-src-da4e70cf9ab3e05f67d77de37a7c6c335a5f7e4b.zip
FreeBSD-src-da4e70cf9ab3e05f67d77de37a7c6c335a5f7e4b.tar.gz
In preparation for raising NGROUPS and NGROUPS_MAX, change base
system callers of getgroups(), getgrouplist(), and setgroups() to allocate buffers dynamically. Specifically, allocate a buffer of size sysconf(_SC_NGROUPS_MAX)+1 (+2 in a few cases to allow for overflow). This (or similar gymnastics) is required for the code to actually follow the POSIX.1-2008 specification where {NGROUPS_MAX} may differ at runtime and where getgroups may return {NGROUPS_MAX}+1 results on systems like FreeBSD which include the primary group. In id(1), don't pointlessly add the primary group to the list of all groups, it is always the first result from getgroups(). In principle the old code was more portable, but this was only done in one of the two places where getgroups() was called to the overall effect was pointless. Document the actual POSIX requirements in the getgroups(2) and setgroups(2) manpages. We do not yet support a dynamic NGROUPS, but we may in the future. MFC after: 2 weeks
Diffstat (limited to 'usr.sbin/chroot')
-rw-r--r--usr.sbin/chroot/chroot.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/usr.sbin/chroot/chroot.c b/usr.sbin/chroot/chroot.c
index f33db7a..cc924a0 100644
--- a/usr.sbin/chroot/chroot.c
+++ b/usr.sbin/chroot/chroot.c
@@ -69,9 +69,10 @@ main(argc, argv)
struct passwd *pw;
char *endp, *p;
const char *shell;
- gid_t gid, gidlist[NGROUPS_MAX];
+ gid_t gid, *gidlist;
uid_t uid;
int ch, gids;
+ long ngroups_max;
gid = 0;
uid = 0;
@@ -117,8 +118,11 @@ main(argc, argv)
}
}
+ ngroups_max = sysconf(_SC_NGROUPS_MAX) + 1;
+ if ((gidlist = malloc(sizeof(gid_t) * ngroups_max)) == NULL)
+ err(1, "malloc");
for (gids = 0;
- (p = strsep(&grouplist, ",")) != NULL && gids < NGROUPS_MAX; ) {
+ (p = strsep(&grouplist, ",")) != NULL && gids < ngroups_max; ) {
if (*p == '\0')
continue;
@@ -135,7 +139,7 @@ main(argc, argv)
}
gids++;
}
- if (p != NULL && gids == NGROUPS_MAX)
+ if (p != NULL && gids == ngroups_max)
errx(1, "too many supplementary groups provided");
if (user != NULL) {
OpenPOWER on IntegriCloud