possible truncated /etc/passwd file
Chris Torek
chris at umcp-cs.UUCP
Wed Sep 17 23:35:46 AEST 1986
In article <185 at uvicctr.UUCP> gduncan at uvicctr.UUCP (Gary Duncan) writes:
>Description:
> the passwd program ... works by creating a temporary copy of the
> updated passwd file by opening /etc/ptmp in exclusive-use mode then
> copying and modifying entries from the original. No problem so far.
> The program then:
> 1. renames the temporary file to /etc/passwd
> 2. closes the stream pointer for the file.
> Unfortunately the exclusive-use mode is lost on rename before the
> stream buffers have been flushed. ...
>Fix:
> Add a fflush(tf) immediately before the rename to flush the buffers.
>
> endpwent();
>+ fflush(tf);
> if (rename(temp, passwd) < 0) {
It would also be a very good idea to check for ferror(tf), in case
the root file system is full. Make that:
endpwent();
(void) fflush(tf);
if (ferror(tf))
/* do something */
This, too, is quite unlikely, but could have drastic consequences.
--
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 1516)
UUCP: seismo!umcp-cs!chris
CSNet: chris at umcp-cs ARPA: chris at mimsy.umd.edu
More information about the Comp.bugs.4bsd.ucb-fixes
mailing list