]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
api.c: fix infinite loop
authorNikola Forró <nforro@redhat.com>
Tue, 8 Dec 2015 15:53:41 +0000 (16:53 +0100)
committerJan Safranek <jsafrane@redhat.com>
Wed, 9 Dec 2015 13:22:00 +0000 (14:22 +0100)
If getgrnam or getpwuid functions failed, the program entered
an infinite loop, because the rule pointer was never advanced.
This is now fixed by updating the pointer before continuing
to the next iteration.

src/api.c

index d6c9d3a954bdf92e5da0e248db41d3f42e033923..ef796acd427e01a2c1e484e989c413936ad8c21c 100644 (file)
--- a/src/api.c
+++ b/src/api.c
@@ -2775,13 +2775,17 @@ static struct cgroup_rule *cgroup_find_matching_rule_uid_gid(uid_t uid,
                        /* Get the group data. */
                        sp = &(rule->username[1]);
                        grp = getgrnam(sp);
-                       if (!grp)
+                       if (!grp) {
+                               rule = rule->next;
                                continue;
+                       }
 
                        /* Get the data for UID. */
                        usr = getpwuid(uid);
-                       if (!usr)
+                       if (!usr) {
+                               rule = rule->next;
                                continue;
+                       }
 
                        /* If UID is a member of group, we matched. */
                        for (i = 0; grp->gr_mem[i]; i++) {