Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F162897719
D44806.id137095.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
D44806.id137095.diff
View Options
diff --git a/bin/cp/utils.c b/bin/cp/utils.c
--- a/bin/cp/utils.c
+++ b/bin/cp/utils.c
@@ -100,21 +100,34 @@
int
copy_file(const FTSENT *entp, int dne)
{
- struct stat *fs;
+ struct stat sb, *fs;
ssize_t wcount;
off_t wtotal;
int ch, checkch, from_fd, rval, to_fd;
int use_copy_file_range = 1;
+ fs = entp->fts_statp;
from_fd = to_fd = -1;
- if (!lflag && !sflag &&
- (from_fd = open(entp->fts_path, O_RDONLY, 0)) == -1) {
- warn("%s", entp->fts_path);
- return (1);
+ if (!lflag && !sflag) {
+ if ((from_fd = open(entp->fts_path, O_RDONLY, 0)) < 0 ||
+ fstat(from_fd, &sb) != 0) {
+ warn("%s", entp->fts_path);
+ return (1);
+ }
+ /*
+ * Check that the file hasn't been replaced with one of a
+ * different type. This can happen if we've been asked to
+ * copy something which is actively being modified and
+ * lost the race, or if we've been asked to copy something
+ * like /proc/X/fd/Y which stat(2) reports as S_IFREG but
+ * is actually something else once you open it.
+ */
+ if ((sb.st_mode & S_IFMT) != (fs->st_mode & S_IFMT)) {
+ warnx("%s: File changed", entp->fts_path);
+ return (1);
+ }
}
- fs = entp->fts_statp;
-
/*
* If the file exists and we're interactive, verify with the user.
* If the file DNE, set the mode to be the from file, minus setuid
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Jul 19, 3:02 AM (6 h, 45 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
35216677
Default Alt Text
D44806.id137095.diff (1 KB)
Attached To
Mode
D44806: cp: Additional sanity check.
Attached
Detach File
Event Timeline
Log In to Comment