From ecaa5ad89f4c9832deb7d0cf7960f363a3c6f068 Mon Sep 17 00:00:00 2001 From: Alan Jenkins Date: Sun, 6 Aug 2017 00:25:19 +0100 Subject: [PATCH] test-condition: fix test_condition_test_group() (#6531) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I hit a test failure with the `max_gid+1` test. Problem is that we loop over 0..r, but set `r` again within the loop (to 1). So max_gid is only set based on the first supplementary GID. ConditionGroup=1000 → 1 ConditionGroup=4 → 1 ConditionGroup=adm → 1 ConditionGroup=1001 → 1 Assertion 'r == 0' failed at ../src/test/test-condition.c:462, function test_condition_test_group(). Aborting. $ id uid=1000(alan-sysop) gid=1000(alan-sysop) groups=1000(alan-sysop),4(adm), 10(wheel),1001(sshlogin) --- src/test/test-condition.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/test-condition.c b/src/test/test-condition.c index b15f1b98c0..278ac2ab6c 100644 --- a/src/test/test-condition.c +++ b/src/test/test-condition.c @@ -402,7 +402,7 @@ static void test_condition_test_group(void) { char* gid; char* groupname; gid_t *gids, max_gid; - int ngroups_max, r, i; + int ngroups_max, ngroups, r, i; assert_se(0 < asprintf(&gid, "%u", UINT32_C(0xFFFF))); condition = condition_new(CONDITION_GROUP, gid, false, false); @@ -427,11 +427,11 @@ static void test_condition_test_group(void) { gids = alloca(sizeof(gid_t) * ngroups_max); - r = getgroups(ngroups_max, gids); - assert(r >= 0); + ngroups = getgroups(ngroups_max, gids); + assert(ngroups >= 0); max_gid = getgid(); - for (i = 0; i < r; i++) { + for (i = 0; i < ngroups; i++) { assert_se(0 < asprintf(&gid, "%u", gids[i])); condition = condition_new(CONDITION_GROUP, gid, false, false); assert_se(condition);