switch to modern source format
[debian/pax] / tar.c
diff --git a/tar.c b/tar.c
index 6a0b3b32963aa4e15685d76a105d04c7626c58ba..2acc32fd5a3b3730b60346c05aa1e51b9861fde2 100644 (file)
--- a/tar.c
+++ b/tar.c
@@ -43,6 +43,7 @@ static const char rcsid[] = "$OpenBSD: tar.c,v 1.41 2006/03/04 20:24:55 otto Exp
 #endif /* not lint */
 
 #include <sys/types.h>
+#include <sys/sysmacros.h>
 #include <sys/time.h>
 #include <sys/stat.h>
 #include <sys/param.h>
@@ -763,6 +764,12 @@ ustar_rd(ARCHD *arcn, char *buf)
        /*
         * see if the filename is split into two parts. if, so joint the parts.
         * we copy the prefix first and add a / between the prefix and name.
+        *
+        * the length passed to l_strncpy must be the length of the field
+        * being copied *from*, since these fields are NOT null terminated
+        * when full.  the destination buffer is plenty big enough to hold
+        * the longest supported ustar path length, so there's no need
+        * to check against that.
         */
        dest = arcn->name;
        if (*(hd->prefix) != '\0') {
@@ -1072,6 +1079,15 @@ ustar_wr(ARCHD *arcn)
        strncpy(hd->uname, name_uid(arcn->sb.st_uid, 0), sizeof(hd->uname));
        strncpy(hd->gname, name_gid(arcn->sb.st_gid, 0), sizeof(hd->gname));
 
+       /*
+        * Always add devmajor and devminor
+        */
+       if (ul_oct ((u_long) MAJOR (arcn->sb.st_rdev), hd->devmajor,
+             sizeof (hd->devmajor), 3) ||
+           ul_oct ((u_long) MINOR (arcn->sb.st_rdev), hd->devminor,
+             sizeof (hd->devminor), 3))
+               goto out;
+
        /*
         * calculate and store the checksum write the header to the archive
         * return 0 tells the caller to now write the file data, 1 says no data