summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authormjg <mjg@FreeBSD.org>2014-10-26 06:04:09 +0000
committermjg <mjg@FreeBSD.org>2014-10-26 06:04:09 +0000
commitf0db1caf67383dba29d4f10235dad3865066e0f5 (patch)
tree48a0362bf140ce8d38a935be24f652a2c67028c9 /sys
parentdb02fb1250bcbb59193620a057eab53313635d3c (diff)
downloadFreeBSD-src-f0db1caf67383dba29d4f10235dad3865066e0f5.zip
FreeBSD-src-f0db1caf67383dba29d4f10235dad3865066e0f5.tar.gz
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.
Diffstat (limited to 'sys')
-rw-r--r--sys/kern/kern_prot.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/sys/kern/kern_prot.c b/sys/kern/kern_prot.c
index 73f6ab7..339c5ff 100644
--- a/sys/kern/kern_prot.c
+++ b/sys/kern/kern_prot.c
@@ -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
OpenPOWER on IntegriCloud