Author: julian
Date: Thu Mar  6 19:26:08 2014
New Revision: 262864
URL: http://svnweb.freebsd.org/changeset/base/262864

Log:
  Stop pw(8) from segfaulting when given certain input
  
  PR:187310
  Submitted by: Kim Shrier
  Obtained from:        bug
  MFC after:    1 week

Modified:
  head/usr.sbin/pw/pw_group.c

Modified: head/usr.sbin/pw/pw_group.c
==============================================================================
--- head/usr.sbin/pw/pw_group.c Thu Mar  6 18:50:35 2014        (r262863)
+++ head/usr.sbin/pw/pw_group.c Thu Mar  6 19:26:08 2014        (r262864)
@@ -227,10 +227,12 @@ pw_group(struct userconf * cnf, int mode
                else if (arg->ch == 'm') {
                        int     k = 0;
 
-                       while (grp->gr_mem[k] != NULL) {
-                               if (extendarray(&members, &grmembers, i + 2) != 
-1)
-                                       members[i++] = grp->gr_mem[k];
-                               k++;
+                       if (grp->gr_mem != NULL) {
+                               while (grp->gr_mem[k] != NULL) {
+                                       if (extendarray(&members, &grmembers, i 
+ 2) != -1)
+                                               members[i++] = grp->gr_mem[k];
+                                       k++;
+                               }
                        }
                }
 
@@ -311,6 +313,9 @@ delete_members(char ***members, int *grm
        int k;
        struct passwd *pwd;
 
+       if (grp->gr_mem == NULL)
+               return;
+
        k = 0;
        while (grp->gr_mem[k] != NULL) {
                matchFound = false;
@@ -415,8 +420,10 @@ print_group(struct group * grp, int pret
                printf("Group Name: %-15s   #%lu\n"
                       "   Members: ",
                       grp->gr_name, (long) grp->gr_gid);
-               for (i = 0; grp->gr_mem[i]; i++)
-                       printf("%s%s", i ? "," : "", grp->gr_mem[i]);
+               if (grp->gr_mem != NULL) {
+                       for (i = 0; grp->gr_mem[i]; i++)
+                               printf("%s%s", i ? "," : "", grp->gr_mem[i]);
+               }
                fputs("\n\n", stdout);
        }
        return EXIT_SUCCESS;
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to