]> granicus.if.org Git - shadow/commitdiff
* src/groupmems.c: When removing an user, check if deluser is on
authornekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Sat, 30 Aug 2008 18:29:08 +0000 (18:29 +0000)
committernekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Sat, 30 Aug 2008 18:29:08 +0000 (18:29 +0000)
the list, not adduser. This fixes a segmentation fault for every
call of groupmems -d.
* libmisc/list.c: Add assertions to help identifying these issues.
* libmisc/list.c: Avoid implicit conversion of pointers to
booleans.

ChangeLog
NEWS
libmisc/list.c
src/groupmems.c

index 6151e4fd4b3f193b6eafc7d1b80f8a7c5e18f0c2..34231bccfc22230f01055a95f2f5d53079883bdf 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2008-08-26  Nicolas François  <nicolas.francois@centraliens.net>
+
+       * src/groupmems.c: When removing an user, check if deluser is on
+       the list, not adduser. This fixes a segmentation fault for every
+       call of groupmems -d.
+       * libmisc/list.c: Add assertions to help identifying these issues.
+       * libmisc/list.c: Avoid implicit conversion of pointers to
+       booleans.
+
 2008-08-26  Nicolas François  <nicolas.francois@centraliens.net>
 
        * NEWS, src/groupmems.c: Use the "groupmems" PAM service name
diff --git a/NEWS b/NEWS
index c60f0d256a35f2f55e7799c2e3364b146af4b088..19500726f7566e31a979167a202922d71098cdcc 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -18,6 +18,7 @@ shadow-4.1.2.1 -> shadow-4.1.3                                                UNRELEASED
     group.
   * Added syslog support.
   * Use the groupmems PAM service name instead of groupmod.
+  * Fix segmentation faults when adding or removing users from a group.
 - newusers
   * Implement the -r, --system option.
 - passwd
index 36b3caf25a6cf21c726ac1e8b8e96f4012153be8..1d0525daac0d5a24fa2528396dd1af16a53796f8 100644 (file)
@@ -50,6 +50,8 @@ char **add_list (char **list, const char *member)
        int i;
        char **tmp;
 
+       assert (NULL != member);
+
        /*
         * Scan the list for the new name.  Return the original list
         * pointer if it is present.
@@ -97,6 +99,8 @@ char **del_list (char **list, const char *member)
        int i, j;
        char **tmp;
 
+       assert (NULL != member);
+
        /*
         * Scan the list for the old name.  Return the original list
         * pointer if it is not present.
@@ -142,12 +146,12 @@ char **dup_list (char *const *list)
        int i;
        char **tmp;
 
-       for (i = 0; list[i]; i++);
+       for (i = 0; NULL != list[i]; i++);
 
        tmp = (char **) xmalloc ((i + 1) * sizeof (char *));
 
        i = 0;
-       while (*list) {
+       while (NULL != *list) {
                tmp[i] = xstrdup (*list);
                i++;
                list++;
@@ -159,12 +163,15 @@ char **dup_list (char *const *list)
 
 bool is_on_list (char *const *list, const char *member)
 {
-       while (*list) {
+       assert (NULL != member);
+
+       while (NULL != *list) {
                if (strcmp (*list, member) == 0) {
                        return true;
                }
                list++;
        }
+
        return false;
 }
 
@@ -179,6 +186,8 @@ char **comma_to_list (const char *comma)
        int i;
        char *cp, *cp2;
 
+       assert (NULL != comma);
+
        /*
         * Make a copy since we are going to be modifying the list
         */
index c1f083de78da82fcbc4f65be01074f02544c1075..b659fe19ca2d10dd89a1fb45eecdec6ac743f7d9 100644 (file)
@@ -291,7 +291,7 @@ int main (int argc, char **argv)
                        fail_exit (13);
                }
        } else if (NULL != deluser) {
-               if (!is_on_list (grp->gr_mem, adduser)) {
+               if (!is_on_list (grp->gr_mem, deluser)) {
                        fprintf (stderr,
                                 _("%s: user '%s' is not a member of '%s'\n"),
                                 Prog, deluser, grp->gr_name);