aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-09-11 16:28:14 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-09-11 16:28:14 +0000
commita9335eafcf113969e807d2aa4381cdd31051099f (patch)
treec37fcddd6653c94ff4b06ea7b64b48b209867f4d
parentfa05074eeed1a6a25393d4b466c7512112f39104 (diff)
downloadbusybox-w32-a9335eafcf113969e807d2aa4381cdd31051099f.tar.gz
busybox-w32-a9335eafcf113969e807d2aa4381cdd31051099f.tar.bz2
busybox-w32-a9335eafcf113969e807d2aa4381cdd31051099f.zip
cp: make it a bit closer to POSIX, but still refuse to open and
write to dest which is a symlink.
-rw-r--r--libbb/copy_file.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/libbb/copy_file.c b/libbb/copy_file.c
index 86449f27c..3da8a3531 100644
--- a/libbb/copy_file.c
+++ b/libbb/copy_file.c
@@ -141,6 +141,8 @@ int copy_file(const char *source, const char *dest, int flags)
141 bb_error_msg("target '%s' is not a directory", dest); 141 bb_error_msg("target '%s' is not a directory", dest);
142 return -1; 142 return -1;
143 } 143 }
144 /* race here: user can substitute a symlink between
145 * this check and actual creation of files inside dest */
144 } else { 146 } else {
145 mode_t mode; 147 mode_t mode;
146 saved_umask = umask(0); 148 saved_umask = umask(0);
@@ -247,13 +249,13 @@ int copy_file(const char *source, const char *dest, int flags)
247 return -1; 249 return -1;
248 250
249 /* POSIX way is a security problem versus symlink attacks, 251 /* POSIX way is a security problem versus symlink attacks,
250 * we do it only for dest's which are device nodes, 252 * we do it only for non-symlinks, and only for non-recursive,
251 * and only for non-recursive, non-interactive cp. NB: it is still racy 253 * non-interactive cp. NB: it is still racy
252 * for "cp file /home/bad_user/device_node" case 254 * for "cp file /home/bad_user/file" case
253 * (user can rm device_node and create link to /etc/passwd) */ 255 * (user can rm file and create a link to /etc/passwd) */
254 if (DO_POSIX_CP 256 if (DO_POSIX_CP
255 || (dest_exists && !(flags & (FILEUTILS_RECUR|FILEUTILS_INTERACTIVE)) 257 || (dest_exists && !(flags & (FILEUTILS_RECUR|FILEUTILS_INTERACTIVE))
256 && (S_ISBLK(dest_stat.st_mode) || S_ISCHR(dest_stat.st_mode))) 258 && !S_ISLNK(dest_stat.st_mode))
257 ) { 259 ) {
258 dst_fd = open(dest, O_WRONLY|O_CREAT|O_TRUNC, source_stat.st_mode); 260 dst_fd = open(dest, O_WRONLY|O_CREAT|O_TRUNC, source_stat.st_mode);
259 } else /* safe way: */ 261 } else /* safe way: */