summaryrefslogtreecommitdiffstats
path: root/bin/cp/cp.c
diff options
context:
space:
mode:
authormckay <mckay@FreeBSD.org>2002-09-22 11:15:56 +0000
committermckay <mckay@FreeBSD.org>2002-09-22 11:15:56 +0000
commit918629fa38ab732596a2a74421013a87dbca6b8d (patch)
treee5b1a0cbc24c17fc075af19e8c07f7fad22f9db5 /bin/cp/cp.c
parent0429db72404985394332f0326307b48592c30b01 (diff)
downloadFreeBSD-src-918629fa38ab732596a2a74421013a87dbca6b8d.zip
FreeBSD-src-918629fa38ab732596a2a74421013a87dbca6b8d.tar.gz
cp -p could report success even if a file copy failed. This was due to
the cumulative exit status being overwritten when directory permissions were being set. This was particularly bad when called from mv(1) to perform a cross-device move as the original files were deleted even if the copy failed. Reported by: Slaven Rezic <slaven.rezic@berlin.de> Patch by: bde PR: 42789
Diffstat (limited to 'bin/cp/cp.c')
-rw-r--r--bin/cp/cp.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/bin/cp/cp.c b/bin/cp/cp.c
index 1007209..57c3e4d 100644
--- a/bin/cp/cp.c
+++ b/bin/cp/cp.c
@@ -361,9 +361,10 @@ copy(char *argv[], enum op type, int fts_options)
* honour setuid, setgid and sticky bits, but we
* normally want to preserve them on directories.
*/
- if (pflag)
- rval = setfile(curr->fts_statp, 0);
- else {
+ if (pflag) {
+ if (setfile(curr->fts_statp, 0))
+ rval = 1;
+ } else {
mode = curr->fts_statp->st_mode;
if ((mode & (S_ISUID | S_ISGID | S_ISTXT)) ||
((mode | S_IRWXU) & mask) != (mode & mask))
OpenPOWER on IntegriCloud