From owner-freebsd-bugs@FreeBSD.ORG Wed Oct 12 00:10:08 2011 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 76BA21065672 for ; Wed, 12 Oct 2011 00:10:08 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id EB83D8FC17 for ; Wed, 12 Oct 2011 00:10:07 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id p9C0A7pT025683 for ; Wed, 12 Oct 2011 00:10:07 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.4/8.14.4/Submit) id p9C0A73x025678; Wed, 12 Oct 2011 00:10:07 GMT (envelope-from gnats) Resent-Date: Wed, 12 Oct 2011 00:10:07 GMT Resent-Message-Id: <201110120010.p9C0A73x025678@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Jeremy Huddleston Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2035A106566B for ; Wed, 12 Oct 2011 00:05:16 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22]) by mx1.freebsd.org (Postfix) with ESMTP id 1021C8FC15 for ; Wed, 12 Oct 2011 00:05:16 +0000 (UTC) Received: from red.freebsd.org (localhost [127.0.0.1]) by red.freebsd.org (8.14.4/8.14.4) with ESMTP id p9C05FTD013539 for ; Wed, 12 Oct 2011 00:05:15 GMT (envelope-from nobody@red.freebsd.org) Received: (from nobody@localhost) by red.freebsd.org (8.14.4/8.14.4/Submit) id p9C05FlL013538; Wed, 12 Oct 2011 00:05:15 GMT (envelope-from nobody) Message-Id: <201110120005.p9C05FlL013538@red.freebsd.org> Date: Wed, 12 Oct 2011 00:05:15 GMT From: Jeremy Huddleston To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: misc/161509: usr.bin/newgrp has an off-by-1 error when checking ngrps X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 12 Oct 2011 00:10:08 -0000 >Number: 161509 >Category: misc >Synopsis: usr.bin/newgrp has an off-by-1 error when checking ngrps >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Wed Oct 12 00:10:07 UTC 2011 >Closed-Date: >Last-Modified: >Originator: Jeremy Huddleston >Release: HEAD >Organization: Apple Inc >Environment: N/A >Description: newgrp.c currently does: if (ngrps == ngrps_max) ... warn about too many groups else ngrps++ setgroups(ngrps, ...) Thus the check for ngrps_max needs to be against ngrps + 1, not ngrps. >How-To-Repeat: call ngrp with your NGROUPS_MAXth group. >Fix: Line numbers will be offset due to local changes. --- newgrp.c (revision 3269) +++ newgrp.c (working copy) @@ -143,7 +146,7 @@ if (initres < 0) warn("initgroups"); if (setres < 0) - warn("setgroups"); + warn("setgid"); } static void @@ -227,7 +250,7 @@ /* Add old effective gid to supp. list if it does not exist. */ if (egid != grp->gr_gid && !inarray(egid, grps, ngrps)) { - if (ngrps == ngrps_max) + if (ngrps + 1 >= ngrps_max) warnx("too many groups"); else { grps[ngrps++] = egid; >Release-Note: >Audit-Trail: >Unformatted: