Article View: net.bugs.4bsd
Article #1718Re: 4.3 rcp can clobber a source file; does not understand host.user:file
From: Ron Natalie <ron>
Date: Thu, 23 Oct 1986 01:39
Date: Thu, 23 Oct 1986 01:39
66 lines
2435 bytes
2435 bytes
Subject: RCP clobbers files.
Index: bin/rcp.c 4.3BSD
Description:
Rcp will silently make a file zero lenght if it is specified
as both the source and destination of a copy. It is difficult
to predict when this will happen as there is no sure way to
verify that two CPU's are in fact using the same filesystem.
In addiiton, when rcp is called with one argument it just silently
exit without saying anything.
Repeat-By:
1. create a file with non-zero lenght called foo on machine host
issue command on host: rcp host:foo foo
the file will now be zero length.
2. type "rcp foo"
Fix:
Make rcp non-destructive in it's copies. Rather than doing an
initial creat, just open the file. Then copy all the blocks.
When the files are the same, each block will be read and written
back into the same place it was read.
Then do an ftruncate to fix up the file length.
Add usage message when too few arguments.
*** 118,123 ****
--- 114,125 ----
}
}
rem = -1;
+
+ if(argc <= 1){
+ fprintf(stderr,"Usage: rcp [-p] f1 f2; or: rcp [-rp] f1...fn d2\n");
+ exit(1);
+ }
+
if (argc > 2)
targetshouldbedirectory = 1;
(void) sprintf(cmd, "rcp%s%s%s",
***************
*** 605,611 ****
}
continue;
}
! if ((of = creat(nambuf, mode)) < 0) {
bad:
error("rcp: %s: %s\n", nambuf, sys_errlist[errno]);
continue;
--- 607,613 ----
}
continue;
}
! if ((of = open(nambuf, O_WRONLY|O_CREAT, mode)) < 0) {
bad:
error("rcp: %s: %s\n", nambuf, sys_errlist[errno]);
continue;
***************
*** 649,654 ****
--- 651,657 ----
if (count != 0 && wrerr == 0 &&
write(of, bp->buf, count) != count)
wrerr++;
+ ftruncate(of, size);
(void) close(of);
(void) response();
if (setimes) {
Technical Details
Message-ID:
<458@brl-sem.ARPA>Path:
arc1-ca.pugleaf.net!utzoo!watmath!clyde!rutgers!seismo!brl-adm!brl-sem!ronReferences:
<1721@emory.UUCP>Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!rutgers!seismo!brl-adm!brl-sem!ron From: ron@brl-sem.ARPA (Ron Natalie <ron>) Newsgroups: net.bugs.4bsd Subject: Re: 4.3 rcp can clobber a source file; does not understand host.user:file Message-ID: <458@brl-sem.ARPA> Date: Wed, 22-Oct-86 20:39:53 EST Article-I.D.: brl-sem.458 Posted: Wed Oct 22 20:39:53 1986 Date-Received: Mon, 27-Oct-86 01:00:07 EST References: <1721@emory.UUCP> Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 66 Keywords: remote copy, bugs, file clobbering