Date: Sun, 26 Oct 2014 06:04:10 +0000 (UTC) From: Mateusz Guzik <mjg@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r273685 - head/sys/kern Message-ID: <201410260604.s9Q64A4x094750@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: mjg Date: Sun Oct 26 06:04:09 2014 New Revision: 273685 URL: https://svnweb.freebsd.org/changeset/base/273685 Log: 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. Modified: head/sys/kern/kern_prot.c Modified: head/sys/kern/kern_prot.c ============================================================================== --- head/sys/kern/kern_prot.c Sun Oct 26 05:39:42 2014 (r273684) +++ head/sys/kern/kern_prot.c Sun Oct 26 06:04:09 2014 (r273685) @@ -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 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 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201410260604.s9Q64A4x094750>