getpwnam bug

sscalsk at nswc-wo.arpa sscalsk at nswc-wo.arpa
Thu Aug 28 02:40:57 AEST 1986


Jim,
	You are correct. Adding a blank line to the head of the passwd file
on a vanilla 4.2BSD system does not have a problem because of the following:
On a vanilla 4.2BSD (which I also have) the routine fgetpwent does not exist.
Is this true for you? (NOTE: fgetpwent takes 1 parm - a file pointer to the 
passwd file). The routine getpwent does all the necessary processing.
Processing of the line read by the fgets is done even if the fgets returned
a line containing only a '\n'. The source shows no further checking on the
contents of the line read by the fgets. In taking a closer look at the code 
on my system it proceeds as follows:

		getpwent: calls
		  fgetpwent: which does the following

		  p=fgets(line, BUFSIZ, f);
		  if (p == NULL)
		    return(NULL);
		  assign pw_name from p
		  p = pwskip(p)
		  assign pw_passwd from p
		  p = pwskip(p)
		  if (p == NULL || *p == ':')
		    return (NULL)

I was incorrect in saying it was the fgets returning the NULL when in fact
it is the final return of the example (after the pwskip processing) that
is returning the NULL. You might also be correct in that it is the SYS III
part of the system that this code is from. It sure doesnt look like vendor
modified code, but not having access to anything but 4.2BSD it is hard to
verify.

Stan Scalsky	Naval Surface Weapons Center - White Oak
ARPA:		sscalsk at nswc-wo.arpa
Compuserve:	70337,2015



More information about the Comp.unix.wizards mailing list