mirror of
https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git
synced 2025-01-01 00:18:15 +01:00
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
This commit is contained in:
parent
3ef5ae2dde
commit
9126964cdb
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=202342
@ -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)
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user