4.3 rcp can clobber a source file; does not understand host.user:file

Ron Natalie <ron> ron at brl-sem.ARPA
Thu Oct 23 11:06:12 AEST 1986


In article <1721 at emory.UUCP>, arnold at emory.UUCP (Arnold D. Robbins {EUCC}) writes:
> Subject: rcp can clobber a file; does not understand host.user:file notation
> Index:	/usr/src/bin/rcp.c 4.3BSD
> 
> Description:
> 	Secondly, rcp can clobber a file by attempting to copy it onto
> 	itself, when a "remote" file is actually a local file. See the
> 	example below. (Admittedly, this is a hole more than a "bug", but
> 	it can be a problem in many environments, particularly where there
> 	are shorthand names. E.g., we have two machines, "emoryu1" and
> 	"emoryu2", with nicknames of "u1" and "u2". I clobbered files a
> 	number of times until I learned to be more careful.)

The better solution, is what we did.
Rather than trying to assure that we are not doing a copy to the source
file, which is very difficult to get right.  We just fixed it so doing
such a copy is not destructive (albeit not very efficient either).  The
way to do this is to not do a creat first if there already exists a file
there.  Then after the copy is done, do a TRUNCATE to make the file the
right length.  This has the effect of just reading and writing all the
blocks in place.

I'll send the code diffs in the normal bug format.

-Ron



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