mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-20 11:11:24 +00:00
Tidy up sys_setgroups and kern_setgroups.
- 'groups' initialization to NULL is always ovewrwriten before use, so plug it - get rid of 'goto out' - kern_setgroups's callers already validate ngrp, so only assert the condition - ngrp is an u_int, so 'ngrp < 1' is more readable as 'ngrp == 0' No functional changes.
This commit is contained in:
parent
92b064f43d
commit
7e9a456a53
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=273685
@ -805,23 +805,24 @@ struct setgroups_args {
|
||||
int
|
||||
sys_setgroups(struct thread *td, struct setgroups_args *uap)
|
||||
{
|
||||
gid_t *groups = NULL;
|
||||
gid_t smallgroups[XU_NGROUPS];
|
||||
gid_t *groups;
|
||||
u_int gidsetsize;
|
||||
int error;
|
||||
|
||||
gidsetsize = uap->gidsetsize;
|
||||
if (gidsetsize > ngroups_max + 1)
|
||||
return (EINVAL);
|
||||
|
||||
if (gidsetsize > XU_NGROUPS)
|
||||
groups = malloc(gidsetsize * sizeof(gid_t), M_TEMP, M_WAITOK);
|
||||
else
|
||||
groups = smallgroups;
|
||||
|
||||
error = copyin(uap->gidset, groups, gidsetsize * sizeof(gid_t));
|
||||
if (error)
|
||||
goto out;
|
||||
error = kern_setgroups(td, gidsetsize, groups);
|
||||
out:
|
||||
if (error == 0)
|
||||
error = kern_setgroups(td, gidsetsize, groups);
|
||||
|
||||
if (gidsetsize > XU_NGROUPS)
|
||||
free(groups, M_TEMP);
|
||||
return (error);
|
||||
@ -834,8 +835,7 @@ kern_setgroups(struct thread *td, u_int ngrp, gid_t *groups)
|
||||
struct ucred *newcred, *oldcred;
|
||||
int error;
|
||||
|
||||
if (ngrp > ngroups_max + 1)
|
||||
return (EINVAL);
|
||||
MPASS(ngrp <= ngroups_max);
|
||||
AUDIT_ARG_GROUPSET(groups, ngrp);
|
||||
newcred = crget();
|
||||
crextend(newcred, ngrp);
|
||||
@ -852,7 +852,7 @@ kern_setgroups(struct thread *td, u_int ngrp, gid_t *groups)
|
||||
if (error)
|
||||
goto fail;
|
||||
|
||||
if (ngrp < 1) {
|
||||
if (ngrp == 0) {
|
||||
/*
|
||||
* setgroups(0, NULL) is a legitimate way of clearing the
|
||||
* groups vector on non-BSD systems (which generally do not
|
||||
|
Loading…
Reference in New Issue
Block a user