]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
Fail if regular file pre-exists in copy_tree()
authorChristian Göttsche <cgzones@googlemail.com>
Fri, 5 Aug 2022 15:57:26 +0000 (17:57 +0200)
committerSerge Hallyn <serge@hallyn.com>
Wed, 17 Aug 2022 17:34:01 +0000 (12:34 -0500)
Similar to the default behavior of mkdir(2), symlink(2), link(2) and
mknod(2).

libmisc/copydir.c

index 648f562a15fe9bd7dd2b7f893375f03e529c4750..90895cfb0e83aa84c326d7e85b02fdc661c44fcc 100644 (file)
@@ -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)