summaryrefslogtreecommitdiff
path: root/bin/cp
diff options
context:
space:
mode:
authorMartijn van Duren <martijn@cvs.openbsd.org>2018-09-07 07:17:15 +0000
committerMartijn van Duren <martijn@cvs.openbsd.org>2018-09-07 07:17:15 +0000
commite9a35428e27300083beca3f3f539ee70f01b4ae1 (patch)
treea8e072ebf4d805a887c4dfe1757a98852a12b539 /bin/cp
parent336f9b4e646707aac115ab8c596a92a31cef5a6d (diff)
Also verify a overwrite for the copy of a fifo, link and device node.
OK stsp@
Diffstat (limited to 'bin/cp')
-rw-r--r--bin/cp/cp.c13
-rw-r--r--bin/cp/utils.c8
2 files changed, 14 insertions, 7 deletions
diff --git a/bin/cp/cp.c b/bin/cp/cp.c
index 6e558e99588..7df43582f5a 100644
--- a/bin/cp/cp.c
+++ b/bin/cp/cp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cp.c,v 1.47 2018/09/07 07:11:16 martijn Exp $ */
+/* $OpenBSD: cp.c,v 1.48 2018/09/07 07:17:14 martijn Exp $ */
/* $NetBSD: cp.c,v 1.14 1995/09/07 06:14:51 jtc Exp $ */
/*
@@ -395,9 +395,9 @@ copy(char *argv[], enum op type, int fts_options)
switch (curr->fts_statp->st_mode & S_IFMT) {
case S_IFLNK:
- if (copy_link(curr, !fts_dne(curr)))
+ if ((cval = copy_link(curr, !fts_dne(curr))) == 1)
rval = 1;
- else if (vflag)
+ if (!cval && vflag)
(void)fprintf(stdout, "%s -> %s\n",
curr->fts_path, to.p_path);
break;
@@ -430,8 +430,8 @@ copy(char *argv[], enum op type, int fts_options)
case S_IFBLK:
case S_IFCHR:
if (Rflag) {
- if (copy_special(curr->fts_statp,
- !fts_dne(curr)))
+ if ((cval = copy_special(curr->fts_statp,
+ !fts_dne(curr))) == 1)
rval = 1;
} else
if ((cval = copy_file(curr, fts_dne(curr))) == 1)
@@ -443,7 +443,8 @@ copy(char *argv[], enum op type, int fts_options)
break;
case S_IFIFO:
if (Rflag) {
- if (copy_fifo(curr->fts_statp, !fts_dne(curr)))
+ if ((cval = copy_fifo(curr->fts_statp,
+ !fts_dne(curr))) == 1)
rval = 1;
} else
if ((cval = copy_file(curr, fts_dne(curr))) == 1)
diff --git a/bin/cp/utils.c b/bin/cp/utils.c
index 8d03cc93c92..1b431f4944e 100644
--- a/bin/cp/utils.c
+++ b/bin/cp/utils.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: utils.c,v 1.42 2018/09/07 07:14:25 martijn Exp $ */
+/* $OpenBSD: utils.c,v 1.43 2018/09/07 07:17:14 martijn Exp $ */
/* $NetBSD: utils.c,v 1.6 1997/02/26 14:40:51 cgd Exp $ */
/*-
@@ -199,6 +199,8 @@ copy_link(FTSENT *p, int exists)
int len;
char name[PATH_MAX];
+ if (exists && !copy_overwrite())
+ return (2);
if ((len = readlink(p->fts_path, name, sizeof(name)-1)) == -1) {
warn("readlink: %s", p->fts_path);
return (1);
@@ -218,6 +220,8 @@ copy_link(FTSENT *p, int exists)
int
copy_fifo(struct stat *from_stat, int exists)
{
+ if (exists && !copy_overwrite())
+ return (2);
if (exists && unlink(to.p_path)) {
warn("unlink: %s", to.p_path);
return (1);
@@ -232,6 +236,8 @@ copy_fifo(struct stat *from_stat, int exists)
int
copy_special(struct stat *from_stat, int exists)
{
+ if (exists && !copy_overwrite())
+ return (2);
if (exists && unlink(to.p_path)) {
warn("unlink: %s", to.p_path);
return (1);