[BusyBox-cvs] busybox/libbb copy_file.c,1.28,1.29

Erik Andersen andersen at busybox.net
Thu Feb 19 00:44:11 UTC 2004


Update of /var/cvs/busybox/libbb
In directory nail:/tmp/cvs-serv19535/libbb

Modified Files:
	copy_file.c 
Log Message:
Chris Larson (kergoth) writes:

I was adding -s/--symbolic-link support to busybox cp when I noticed a
bug with -r/-a.  Test case:

mkdir -p test/out
cd test
busybox cp -a * out/

Will never return until we run out of open files or similar.
Coreutils cp on the other hand will error with "cannot copy a directory,
`out', into itself, `out'".  Patch attached.



Index: copy_file.c
===================================================================
RCS file: /var/cvs/busybox/libbb/copy_file.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- copy_file.c	11 Jan 2004 05:20:59 -0000	1.28
+++ copy_file.c	19 Feb 2004 00:44:08 -0000	1.29
@@ -65,12 +65,28 @@
 		DIR *dp;
 		struct dirent *d;
 		mode_t saved_umask = 0;
+		char *dstparent;
+		struct stat dstparent_stat;
 
 		if (!(flags & FILEUTILS_RECUR)) {
 			bb_error_msg("%s: omitting directory", source);
 			return -1;
 		}
 
+		dstparent = dirname(bb_xstrdup(dest));
+		if (lstat(dstparent, &dstparent_stat) < 0) {
+			bb_perror_msg("unable to stat `%s'", dstparent);
+			free(dstparent);
+			return -1;
+		}
+		free(dstparent);
+
+		if (source_stat.st_dev == dstparent_stat.st_dev &&
+			source_stat.st_ino == dstparent_stat.st_ino) {
+			bb_error_msg("cannot copy a directory, `%s', into itself, `%s'", source, dest);
+			return -1;
+		}
+
 		/* Create DEST.  */
 		if (dest_exists) {
 			if (!S_ISDIR(dest_stat.st_mode)) {




More information about the busybox-cvs mailing list