bug in 4.1BSD compact

jonab at sdcrdcf.UUCP jonab at sdcrdcf.UUCP
Wed Jun 29 04:08:08 AEST 1983


The program "compact" from UNIX 4.1BSD has a bug that makes it possible for it
to loose a file if it receives a signal at the wrong time.  It unlinks
the original file before it fcloses the compacted file; thus if it is
compacting a short file, it is possible to loose both the uncompacted
and compacted versions if it receives a signal after it has unlinked
but before it has fclosed the compacted file.  The process will terminate
without flushing the data that is to be written to the compacted file.
One is then left with a zero length compacted file.  Following is the
required patch:

change the lines just before the closeboth label:
			    ...
			    if (i >= argc) break;
			    unlink (argv [i]);
		closeboth : fclose (cfp);
			    ...

to read:
			    ...
			    if (i >= argc) break;
			    fclose(cfp);
			    unlink (argv [i]);
			    goto closein;
		closeboth : fclose (cfp);
			    ...

This will make sure the buffer is flushed before it unlinks the original
file.

					Jon Biggar



More information about the Comp.bugs.4bsd.ucb-fixes mailing list