]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-condition: fix test_condition_test_group() (#6531)
authorAlan Jenkins <alan.christopher.jenkins@gmail.com>
Sat, 5 Aug 2017 23:25:19 +0000 (00:25 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 5 Aug 2017 23:25:19 +0000 (19:25 -0400)
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

index b15f1b98c07d8b956688c465ed93631fc11652d7..278ac2ab6cb68f57eb2c704811e96b459a5abe4a 100644 (file)
@@ -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);