diff options
author | brooks <brooks@FreeBSD.org> | 2010-01-15 07:18:46 +0000 |
---|---|---|
committer | brooks <brooks@FreeBSD.org> | 2010-01-15 07:18:46 +0000 |
commit | c67fa34ee5c440057e9c69882e34f7b0175c0d65 (patch) | |
tree | 92e99e071d3885a47f5fe1a2f6d26e93de1dbe86 | |
parent | f354ae0814810e4c8aeeea7b9765ba2b6b7d51b2 (diff) | |
download | FreeBSD-src-c67fa34ee5c440057e9c69882e34f7b0175c0d65.zip FreeBSD-src-c67fa34ee5c440057e9c69882e34f7b0175c0d65.tar.gz |
Only allocate the space we need before calling kern_getgroups instead
of allocating what ever the user asks for up to "ngroups_max + 1". On
systems with large values of kern.ngroups this will be more efficient.
The now redundant check that the array is large enough in
kern_getgroups() is deliberate to allow this change to be merged to
stable/8 without breaking potential third party consumers of the API.
Reported by: bde
MFC after: 28 days
-rw-r--r-- | sys/i386/ibcs2/ibcs2_misc.c | 10 | ||||
-rw-r--r-- | sys/kern/kern_prot.c | 8 |
2 files changed, 14 insertions, 4 deletions
diff --git a/sys/i386/ibcs2/ibcs2_misc.c b/sys/i386/ibcs2/ibcs2_misc.c index 6d25937..c537100 100644 --- a/sys/i386/ibcs2/ibcs2_misc.c +++ b/sys/i386/ibcs2/ibcs2_misc.c @@ -663,9 +663,13 @@ ibcs2_getgroups(td, uap) u_int i, ngrp; int error; - if (uap->gidsetsize < 0) - return (EINVAL); - ngrp = MIN(uap->gidsetsize, ngroups_max + 1); + if (uap->gidsetsize < td->td_ucred->cr_ngroups) { + if (uap->gidsetsize == 0) + ngrp = 0; + else + return (EINVAL); + } else + ngrp = td->td_ucred->cr_ngroups; gp = malloc(ngrp * sizeof(*gp), M_TEMP, M_WAITOK); error = kern_getgroups(td, &ngrp, gp); if (error) diff --git a/sys/kern/kern_prot.c b/sys/kern/kern_prot.c index 5a5c24c..16b0f37 100644 --- a/sys/kern/kern_prot.c +++ b/sys/kern/kern_prot.c @@ -283,7 +283,13 @@ getgroups(struct thread *td, register struct getgroups_args *uap) u_int ngrp; int error; - ngrp = MIN(uap->gidsetsize, ngroups_max + 1); + if (uap->gidsetsize < td->td_ucred->cr_ngroups) { + if (uap->gidsetsize == 0) + ngrp = 0; + else + return (EINVAL); + } else + ngrp = td->td_ucred->cr_ngroups; groups = malloc(ngrp * sizeof(*groups), M_TEMP, M_WAITOK); error = kern_getgroups(td, &ngrp, groups); if (error) |