From owner-svn-src-all@FreeBSD.ORG Fri Jan 15 07:18:46 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B596A106566C; Fri, 15 Jan 2010 07:18:46 +0000 (UTC) (envelope-from brooks@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 8B9308FC19; Fri, 15 Jan 2010 07:18:46 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o0F7IkXn084384; Fri, 15 Jan 2010 07:18:46 GMT (envelope-from brooks@svn.freebsd.org) Received: (from brooks@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o0F7IkTM084381; Fri, 15 Jan 2010 07:18:46 GMT (envelope-from brooks@svn.freebsd.org) Message-Id: <201001150718.o0F7IkTM084381@svn.freebsd.org> From: Brooks Davis Date: Fri, 15 Jan 2010 07:18:46 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r202342 - in head/sys: i386/ibcs2 kern X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 15 Jan 2010 07:18:46 -0000 Author: brooks Date: Fri Jan 15 07:18:46 2010 New Revision: 202342 URL: http://svn.freebsd.org/changeset/base/202342 Log: 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 Modified: head/sys/i386/ibcs2/ibcs2_misc.c head/sys/kern/kern_prot.c Modified: head/sys/i386/ibcs2/ibcs2_misc.c ============================================================================== --- head/sys/i386/ibcs2/ibcs2_misc.c Fri Jan 15 07:05:00 2010 (r202341) +++ head/sys/i386/ibcs2/ibcs2_misc.c Fri Jan 15 07:18:46 2010 (r202342) @@ -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) Modified: head/sys/kern/kern_prot.c ============================================================================== --- head/sys/kern/kern_prot.c Fri Jan 15 07:05:00 2010 (r202341) +++ head/sys/kern/kern_prot.c Fri Jan 15 07:18:46 2010 (r202342) @@ -283,7 +283,13 @@ getgroups(struct thread *td, register st 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)