hubert@entropy.UUCP (Steve Hubert) (10/28/86)
Subject: getusershell() is buggy Index: lib/libc/gen/getusershell.c 4.3BSD Description: Getusershell(3) does not handle comments correctly. Setusershell(3) does not work at all. Repeat-By: Run the following program with the default version of /etc/shells. Notice that the first shell printed out is /passwd. This comes from one of the leading comments in the file /etc/shells. Also notice that setusershell() does not rewind the shells file so nothing is printed out in the second loop. main() { char *cp, *getusershell(); for (cp = getusershell(); cp; cp = getusershell()) printf("%s\n", cp); setusershell(); for (cp = getusershell(); cp; cp = getusershell()) printf("%s\n", cp); } Fix: There was a fix posted as 4573@brl-smoke.ARPA to netnews. That fix (as received at my site) was obviously incorrect since it didn't work and it contained a line of code that looked like: while (!isspace(*cp) != '/' && *cp != '\0') Here is a context diff (to the original getusershell.c) to fix the problem. *** getusershell.c.old Mon Oct 27 17:17:05 1986 --- getusershell.c.new Mon Oct 27 17:17:05 1986 *************** *** 58,64 **** setusershell() { ! shells = initshells(); } static char ** --- 58,64 ---- setusershell() { ! endusershell(); } static char ** *************** *** 96,101 **** --- 96,103 ---- sp = shells; cp = strings; while (fgets(cp, MAXPATHLEN + 1, fp) != NULL) { + if (*cp == '#') + continue; while (*cp != '/' && *cp != '\0') cp++; if (*cp == '\0')