Part 2 of bug 187310.. had to commit separately due to local confusion.

Don't let pw crash when give certain input.

PR:		187310
Submitted by:	Kim Shrier
MFC after:	1 week
This commit is contained in:
Julian Elischer 2014-03-06 19:58:03 +00:00
parent 5691bbf05d
commit bbd054cb33
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=262865

View File

@ -425,19 +425,22 @@ pw_user(struct userconf * cnf, int mode, struct cargs * args)
}
grp = GETGRNAM(a_name->val);
if (grp != NULL && *grp->gr_mem == NULL)
if (grp != NULL &&
(grp->gr_mem == NULL || *grp->gr_mem == NULL))
delgrent(GETGRNAM(a_name->val));
SETGRENT();
while ((grp = GETGRENT()) != NULL) {
int i;
char group[MAXLOGNAME];
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];
}
strlcpy(group, grp->gr_name, MAXLOGNAME);
chggrent(group, grp);
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];
}
strlcpy(group, grp->gr_name, MAXLOGNAME);
chggrent(group, grp);
}
}
}
}
@ -908,7 +911,8 @@ pw_gidpolicy(struct userconf * cnf, struct cargs * args, char *nam, gid_t prefer
errx(EX_NOUSER, "group `%s' is not defined", a_gid->val);
}
gid = grp->gr_gid;
} else if ((grp = GETGRNAM(nam)) != NULL && grp->gr_mem[0] == NULL) {
} else if ((grp = GETGRNAM(nam)) != NULL &&
(grp->gr_mem == NULL || grp->gr_mem[0] == NULL)) {
gid = grp->gr_gid; /* Already created? Use it anyway... */
} else {
struct cargs grpargs;
@ -1182,14 +1186,16 @@ print_user(struct passwd * pwd, int pretty, int v7)
while ((grp=GETGRENT()) != NULL)
{
int i = 0;
while (grp->gr_mem[i] != NULL)
{
if (strcmp(grp->gr_mem[i], pwd->pw_name)==0)
if (grp->gr_mem != NULL) {
while (grp->gr_mem[i] != NULL)
{
printf(j++ == 0 ? " Groups: %s" : ",%s", grp->gr_name);
break;
if (strcmp(grp->gr_mem[i], pwd->pw_name)==0)
{
printf(j++ == 0 ? " Groups: %s" : ",%s", grp->gr_name);
break;
}
++i;
}
++i;
}
}
ENDGRENT();