HardenedBSD/bin
Dag-Erling Smørgrav 0729d1e8fd cp: Never follow symbolic links in destination.
Historically, BSD cp has followed symbolic links in the destination
when copying recursively, while GNU cp has not.  POSIX is somewhat
vague on the topic, but both interpretations are within bounds.  In
33ad990ce9, cp was changed to apply the same logic for symbolic
links in the destination as for symbolic links in the source: follow
if not recursing (which is moot, as this situation can only arise
while recursing) or if the `-L` option was given.  There is no support
for this in POSIX.  We can either switch back, or go all the way.

Having carefully weighed the kind of trouble you can run into by
following unexpected symlinks up against the kind of trouble you can
run into by not following symlinks you expected to follow, we choose
to go all the way.

Note that this means we need to stat the destination twice: once,
following links, to check if it is or references the same file as the
source, and a second time, not following links, to set the dne flag
and determine the destination's type.

While here, remove a needless complication in the dne logic.  We don't
need to explicitly reject overwriting a directory with a non-directory,
because it will fail anyway.

Finally, add test cases for copying a directory to a symlink and
overwriting a directory with a non-directory.

MFC after:	never
Relnotes: 	yes
Sponsored by:	Klara, Inc.
Reviewed by:	kevans
Differential Revision:	https://reviews.freebsd.org/D44578
2024-04-09 00:41:33 +02:00
..
cat cat: fix cap_rights_init usage 2024-02-14 19:37:54 -05:00
chflags
chio
chmod
cp cp: Never follow symbolic links in destination. 2024-04-09 00:41:33 +02:00
cpuset
csh csh: Use HOST_CC when compiling hostprog used by csh build 2024-03-27 18:21:50 -04:00
date date(1): Grammar fixes 2024-02-13 19:00:59 +08:00
dd
df df(1): Fix grammar 2024-02-13 18:31:05 +08:00
domainname domainname(1): Grammar fix 2024-02-13 19:13:33 +08:00
echo echo(1): Add EXAMPLES 2024-04-08 18:35:40 +02:00
ed
expr
freebsd-version
getfacl
hostname tests: Fixing incomplete atf_skip if missing jail condition 2024-02-23 13:08:09 +01:00
kenv
kill
ln ln: Improve link(1) variant of ln(1). 2024-04-04 16:14:50 +02:00
ls ls.1: Mention CLICOLOR environment variable 2024-02-21 11:54:58 +01:00
mkdir
mv
nproc
pax
pkill
ps
pwait
pwd
realpath
rm
rmail
rmdir
setfacl
sh
sleep sleep: Overhaul. 2024-03-25 16:59:02 +01:00
stty
sync
test
tests
timeout
uuidgen
Makefile
Makefile.inc