From patchwork Thu Apr 4 19:20:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Gerow X-Patchwork-Id: 32169 Received: (qmail 94934 invoked by alias); 4 Apr 2019 19:20:55 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 94926 invoked by uid 89); 4 Apr 2019 19:20:55 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-30.8 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH, FSL_HELO_FAKE, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS, USER_IN_DEF_SPF_WL autolearn=ham version=3.3.1 spammy=HX-Received:a81, HX-Spam-Relays-External:sk:mail-yw, H*r:sk:mail-yw, HX-HELO:sk:mail-yw X-HELO: mail-yw1-f41.google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=JFehzARVL8uZ3sup8oR+C+iTh1yUEiplNrIsknjn8ag=; b=C+i/nS0/pIhUy76oG1zI+PEmSJyY9JvflbSqW1LtzghakFZZvthJNqqA+B+u7U933y rSWVfSzdZiuTZVTAqmNC1pneAabutsNg8dURc7qacIUc7ILvB9djwpuqRrPUmaHaL/qm k72d0yl14a3sMEyiRersFyibj8UAOLbK1XYjajlWTwOv8h05wAAKBHcyDLe0cQPEIkqW 4sf34BlG3EcgsloiGW5Xk8nZ1EZUZH76Ep0ac0wDsTCL1S02ppyJLMdzYJrpT8MGRN2A knm+aSNSPWvNJ4Il0DskzARJiHnPTvjgVdO6JsCNeXgaJgqe0xiWSZtuEFg2M39BM4fT Sm2w== Return-Path: Date: Thu, 4 Apr 2019 12:20:47 -0700 From: Mike Gerow To: libc-alpha@sourceware.org Cc: gerow@google.com Subject: [PATCH 1/1] stdlib/tst-secure-getenv: handle >64 groups Message-ID: <20190404192047.GA108564@google.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) This test would fail unnecessarily if the user running it had more than 64 groups since getgroups returns EINVAL if the size provided is less than the number of supplementary group IDs. Instead dynamically determine the number of supplementary groups the user has. --- stdlib/tst-secure-getenv.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/stdlib/tst-secure-getenv.c b/stdlib/tst-secure-getenv.c index 74580b889a..178dfa0439 100644 --- a/stdlib/tst-secure-getenv.c +++ b/stdlib/tst-secure-getenv.c @@ -41,8 +41,14 @@ static char MAGIC_ARGUMENT[] = "run-actual-test"; static gid_t choose_gid (void) { - const int count = 64; - gid_t groups[count]; + int count = getgroups (0, NULL); + if (count < 0) + { + printf ("getgroups: %m\n"); + exit (1); + } + gid_t *groups; + groups = malloc (count * sizeof (*groups)); int ret = getgroups (count, groups); if (ret < 0) { @@ -50,12 +56,17 @@ choose_gid (void) exit (1); } gid_t current = getgid (); + gid_t not_current = 0; for (int i = 0; i < ret; ++i) { if (groups[i] != current) - return groups[i]; + { + not_current = groups[i]; + break; + } } - return 0; + free (groups); + return not_current; }