Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 6 Mar 2014 19:26:08 +0000 (UTC)
From:      Julian Elischer <julian@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r262864 - head/usr.sbin/pw
Message-ID:  <201403061926.s26JQ8Qh061072@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
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;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201403061926.s26JQ8Qh061072>