diff --git a/misc/getusershell.c b/misc/getusershell.c index fc2c43b..44143dc 100644 --- a/misc/getusershell.c +++ b/misc/getusershell.c @@ -119,7 +119,7 @@ initshells (void) flen = statb.st_size + 3; if ((strings = malloc(flen)) == NULL) goto init_okshells; - shells = malloc(statb.st_size / 3 * sizeof (char *)); + shells = malloc(((statb.st_size / 3) + 2) * sizeof (char *)); if (shells == NULL) { free(strings); strings = NULL; @@ -130,7 +130,8 @@ initshells (void) while (fgets_unlocked(cp, flen - (cp - strings), fp) != NULL) { while (*cp != '#' && *cp != '/' && *cp != '\0') cp++; - if (*cp == '#' || *cp == '\0' || cp[1] == '\0') + /* Reject non-absolute paths, or anything too short. */ + if (cp[0] != '/' || cp[1] == '\0' || isspace(cp[1])) continue; *sp++ = cp; while (!isspace(*cp) && *cp != '#' && *cp != '\0')