if (!S_ISREG(source_stat.st_mode))
new_mode = 0666;
- // POSIX way is a security problem versus (sym)link attacks
- if (!ENABLE_FEATURE_NON_POSIX_CP) {
- dst_fd = open(dest, O_WRONLY|O_CREAT|O_TRUNC, new_mode);
- } else { /* safe way: */
+ if (ENABLE_FEATURE_NON_POSIX_CP || (flags & FILEUTILS_INTERACTIVE)) {
+ /*
+ * O_CREAT|O_EXCL: require that file did not exist before creation
+ */
dst_fd = open(dest, O_WRONLY|O_CREAT|O_EXCL, new_mode);
+ } else { /* POSIX, and not "cp -i" */
+ /*
+ * O_CREAT|O_TRUNC: create, or truncate (security problem versus (sym)link attacks)
+ */
+ dst_fd = open(dest, O_WRONLY|O_CREAT|O_TRUNC, new_mode);
}
if (dst_fd == -1) {
ovr = ask_and_unlink(dest, flags);