From patchwork Sat Sep 25 17:47:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Gongyi X-Patchwork-Id: 1533677 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HJPp70h1wz9t2p for ; Tue, 28 Sep 2021 13:17:51 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 30B0E3CA0CD for ; Tue, 28 Sep 2021 05:17:48 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-3.smtp.seeweb.it (in-3.smtp.seeweb.it [217.194.8.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 0E9843C71C8 for ; Tue, 28 Sep 2021 05:17:45 +0200 (CEST) Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-3.smtp.seeweb.it (Postfix) with ESMTPS id ECA211A00A36 for ; Tue, 28 Sep 2021 05:17:43 +0200 (CEST) Received: from dggeml753-chm.china.huawei.com (unknown [172.30.72.56]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4HJPmx5Tqtz8tLx for ; Tue, 28 Sep 2021 11:16:49 +0800 (CST) Received: from ubuntu1804.huawei.com (10.67.174.63) by dggeml753-chm.china.huawei.com (10.1.199.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.8; Tue, 28 Sep 2021 11:17:40 +0800 From: Zhao Gongyi To: Date: Sun, 26 Sep 2021 01:47:03 +0800 Message-ID: <20210925174703.7675-1-zhaogongyi@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-Originating-IP: [10.67.174.63] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggeml753-chm.china.huawei.com (10.1.199.152) X-CFilter-Loop: Reflected X-Virus-Scanned: clamav-milter 0.102.4 at in-3.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.0 required=7.0 tests=SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-3.smtp.seeweb.it Subject: [LTP] [PATCH] setgroups03: Fix running more iterations (-i 2) X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" When run the test with option "-i 2", test will fail and report "setgroups03.c:157: setgroups(65537) fails, Size is > sysconf(_SC_NGROUPS_MAX), errno=1, expected errno=22". Signed-off-by: Zhao Gongyi --- .../kernel/syscalls/setgroups/setgroups03.c | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) -- 2.17.1 diff --git a/testcases/kernel/syscalls/setgroups/setgroups03.c b/testcases/kernel/syscalls/setgroups/setgroups03.c index 490b06996..3ddea5635 100644 --- a/testcases/kernel/syscalls/setgroups/setgroups03.c +++ b/testcases/kernel/syscalls/setgroups/setgroups03.c @@ -88,6 +88,7 @@ GID_T *groups_list; /* Array to hold gids for getgroups() */ int setup1(); /* setup function to test error EPERM */ void setup(); /* setup function for the test */ +void cleanup1(); /* cleanup function for setup1 */ void cleanup(); /* cleanup function for the test */ struct test_case_t { /* test case struct. to hold ref. test cond's */ @@ -156,6 +157,9 @@ int main(int ac, char **av) gidsetsize, test_desc, TEST_ERRNO, Test_cases[i].exp_errno); } + if (Test_cases[i].setupfunc != NULL) { + cleanup1(); + } } } @@ -191,7 +195,7 @@ int setup1(void) { struct passwd *user_info; /* struct. to hold test user info */ -/* Switch to nobody user for correct error code collection */ + /* Switch to nobody user for correct error code collection */ ltpuser = getpwnam(nobody_uid); if (seteuid(ltpuser->pw_uid) == -1) { tst_resm(TINFO, "setreuid failed to " @@ -212,6 +216,24 @@ int setup1(void) return 0; } +void cleanup1(void) +{ + struct passwd *user_info; + if (seteuid(0) < 0) + tst_brkm(TBROK, cleanup, "seteuid failed"); + + if ((user_info = getpwnam("root")) == NULL) + tst_brkm(TBROK, cleanup, "getpwnam(2) of root Failed"); + + if (!GID_SIZE_CHECK(user_info->pw_gid)) { + tst_brkm(TBROK, + cleanup, + "gid returned from getpwnam is too large for testing setgroups16"); + } + + groups_list[0] = user_info->pw_gid; +} + /* * cleanup() - performs all ONE TIME cleanup for this test at * completion or premature exit.