From owner-svn-src-head@FreeBSD.ORG Sun Oct 26 06:04:10 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id DD4F5AF9; Sun, 26 Oct 2014 06:04:10 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id B00B8E60; Sun, 26 Oct 2014 06:04:10 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id s9Q64AlJ094751; Sun, 26 Oct 2014 06:04:10 GMT (envelope-from mjg@FreeBSD.org) Received: (from mjg@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id s9Q64A4x094750; Sun, 26 Oct 2014 06:04:10 GMT (envelope-from mjg@FreeBSD.org) Message-Id: <201410260604.s9Q64A4x094750@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: mjg set sender to mjg@FreeBSD.org using -f From: Mateusz Guzik Date: Sun, 26 Oct 2014 06:04:10 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r273685 - head/sys/kern X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 26 Oct 2014 06:04:11 -0000 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