From: Christian Göttsche Date: Fri, 5 Aug 2022 15:57:26 +0000 (+0200) Subject: Fail if regular file pre-exists in copy_tree() X-Git-Tag: 4.12.2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1d281273b149f2bb992d893d8ca9ffffddc95cc8;p=thirdparty%2Fshadow.git Fail if regular file pre-exists in copy_tree() Similar to the default behavior of mkdir(2), symlink(2), link(2) and mknod(2). --- diff --git a/libmisc/copydir.c b/libmisc/copydir.c index 648f562a1..90895cfb0 100644 --- a/libmisc/copydir.c +++ b/libmisc/copydir.c @@ -723,7 +723,7 @@ static int copy_file (const char *src, const char *dst, return -1; } #endif /* WITH_SELINUX */ - ofd = open (dst, O_WRONLY | O_CREAT | O_TRUNC | O_NOFOLLOW, statp->st_mode & 07777); + ofd = open (dst, O_WRONLY | O_CREAT | O_EXCL | O_TRUNC | O_NOFOLLOW | O_CLOEXEC, statp->st_mode & 07777); if ( (ofd < 0) || (fchown_if_needed (ofd, statp, old_uid, new_uid, old_gid, new_gid) != 0)