]> git.cameronkatri.com Git - pw-darwin.git/commitdiff
pw: fix up deletion of users from groups
authorMateusz Guzik <mjg@FreeBSD.org>
Fri, 27 Jun 2014 18:51:19 +0000 (18:51 +0000)
committerMateusz Guzik <mjg@FreeBSD.org>
Fri, 27 Jun 2014 18:51:19 +0000 (18:51 +0000)
Previuosly given 'foo,bar' members, removing 'foo' would result in an
infinite loop.

PR: 191427
Submitted by: Voradesh Yenbut <yenbut cs.washington.edu>
MFC after: 1 week

pw/pw_user.c

index 4b3f55007f6b6ec3785df203f6005c17b9a7519d..36c5d9df527c0f9696c08d43f2bf4d9505a04ad7 100644 (file)
@@ -438,14 +438,13 @@ pw_user(struct userconf * cnf, int mode, struct cargs * args)
                                delgrent(GETGRNAM(a_name->val));
                        SETGRENT();
                        while ((grp = GETGRENT()) != NULL) {
-                               int i;
+                               int i, j;
                                char group[MAXLOGNAME];
                                if (grp->gr_mem != NULL) {
                                        for (i = 0; grp->gr_mem[i] != NULL; i++) {
                                                if (!strcmp(grp->gr_mem[i], a_name->val)) {
-                                                       while (grp->gr_mem[i] != NULL) {
-                                                               grp->gr_mem[i] = grp->gr_mem[i+1];
-                                                       }       
+                                                       for (j = i; grp->gr_mem[j] != NULL; j++)
+                                                               grp->gr_mem[j] = grp->gr_mem[j+1];
                                                        strlcpy(group, grp->gr_name, MAXLOGNAME);
                                                        chggrent(group, grp);
                                                }