summaryrefslogtreecommitdiffstats
path: root/gnu/usr.bin/cpio
diff options
context:
space:
mode:
authorbde <bde@FreeBSD.org>1995-09-12 16:38:16 +0000
committerbde <bde@FreeBSD.org>1995-09-12 16:38:16 +0000
commit05ba62283064c2394339fa3975fe9a4da67c12a9 (patch)
treee6ac32dc565c88a9fe23abecebcbcedbbd40b800 /gnu/usr.bin/cpio
parent7f65a388a815a2a06aed6df0d3c67777ffe96d0e (diff)
downloadFreeBSD-src-05ba62283064c2394339fa3975fe9a4da67c12a9.zip
FreeBSD-src-05ba62283064c2394339fa3975fe9a4da67c12a9.tar.gz
Output a zero rdev except for bdevs, cdevs, fifos and sockets. This
stops regular files with unrepresentable rdevs from being rejected and makes the output independent of unpreservable metadata.
Diffstat (limited to 'gnu/usr.bin/cpio')
-rw-r--r--gnu/usr.bin/cpio/copyout.c28
1 files changed, 26 insertions, 2 deletions
diff --git a/gnu/usr.bin/cpio/copyout.c b/gnu/usr.bin/cpio/copyout.c
index 933e4da..77053d9 100644
--- a/gnu/usr.bin/cpio/copyout.c
+++ b/gnu/usr.bin/cpio/copyout.c
@@ -294,8 +294,32 @@ process_copy_out ()
file_hdr.c_uid = file_stat.st_uid;
file_hdr.c_gid = file_stat.st_gid;
file_hdr.c_nlink = file_stat.st_nlink;
- file_hdr.c_rdev_maj = major (file_stat.st_rdev);
- file_hdr.c_rdev_min = minor (file_stat.st_rdev);
+
+ /* The rdev is meaningless except for block and character
+ special files (POSIX standard) and perhaps fifos and
+ sockets. Clear it for other types of files so that
+ check_rdev() doesn't reject files just because stat()
+ put garbage in st_rdev and so that the output doesn't
+ depend on the garbage. */
+ switch (file_hdr.c_mode & CP_IFMT)
+ {
+ case CP_IFBLK:
+ case CP_IFCHR:
+#ifdef CP_IFIFO
+ case CP_IFIFO:
+#endif
+#ifdef CP_IFSOCK
+ case CP_IFSOCK:
+#endif
+ file_hdr.c_rdev_maj = major (file_stat.st_rdev);
+ file_hdr.c_rdev_min = minor (file_stat.st_rdev);
+ break;
+ default:
+ file_hdr.c_rdev_maj = 0;
+ file_hdr.c_rdev_min = 0;
+ break;
+ }
+
file_hdr.c_mtime = file_stat.st_mtime;
file_hdr.c_filesize = file_stat.st_size;
file_hdr.c_chksum = 0;
OpenPOWER on IntegriCloud