Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!rutgers!seismo!brl-adm!brl-sem!ron From: ron@brl-sem.ARPA (Ron Natalie ) Newsgroups: net.bugs.4bsd Subject: Re: 4.3 rcp can clobber a source file; does not understand host.user:file Message-ID: <456@brl-sem.ARPA> Date: Wed, 22-Oct-86 20:06:12 EST Article-I.D.: brl-sem.456 Posted: Wed Oct 22 20:06:12 1986 Date-Received: Mon, 27-Oct-86 00:59:09 EST References: <1721@emory.UUCP> Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 25 Keywords: remote copy, bugs, file clobbering In article <1721@emory.UUCP>, arnold@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