bin/66492: cpio -o -Hustar creates broken timestamps

Christian Weisgerber naddy at FreeBSD.org
Mon May 10 13:10:18 PDT 2004


>Number:         66492
>Category:       bin
>Synopsis:       cpio -o -Hustar creates broken timestamps
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon May 10 13:10:14 PDT 2004
>Closed-Date:
>Last-Modified:
>Originator:     Christian Weisgerber
>Release:        FreeBSD 5.2-CURRENT alpha
>Organization:
>Environment:
System: FreeBSD kemoauc.mips.inka.de 5.2-CURRENT FreeBSD 5.2-CURRENT #1: Tue May 4 13:37:55 CEST 2004 naddy at kemoauc.mips.inka.de:/usr/obj/usr/src/sys/KEMOAUC alpha

>Description:

The cpio(1) command creates broken timestamps for ustar format archives.
For additional details, see Debian bug report #238177:
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=238177

>How-To-Repeat:

$ touch foo
$ echo foo | cpio -o -Hustar >foo.tar
$ cpio -itv < foo.tar
...
$ tar tvf foo.tar
...

>Fix:

>From David Kimdon <dwhedon at debian.org>:

Index: tar.c
===================================================================
RCS file: /home/ncvs/src/contrib/cpio/tar.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 tar.c
--- tar.c	29 Mar 1997 22:40:44 -0000	1.1.1.1
+++ tar.c	10 May 2004 19:57:20 -0000
@@ -27,6 +27,7 @@
 #include "tarhdr.h"
 
 static void to_oct ();
+static void to_oct_no_nul ();
 static char *stash_tar_linkname ();
 static char *stash_tar_filename ();
 
@@ -97,8 +98,8 @@
   to_oct (file_hdr->c_mode, 8, tar_hdr->mode);
   to_oct (file_hdr->c_uid, 8, tar_hdr->uid);
   to_oct (file_hdr->c_gid, 8, tar_hdr->gid);
-  to_oct (file_hdr->c_filesize, 12, tar_hdr->size);
-  to_oct (file_hdr->c_mtime, 12, tar_hdr->mtime);
+  to_oct_no_nul (file_hdr->c_filesize, 12, tar_hdr->size);
+  to_oct_no_nul (file_hdr->c_mtime, 12, tar_hdr->mtime);
 
   switch (file_hdr->c_mode & CP_IFMT)
     {
@@ -443,6 +444,21 @@
     where[--digits] = ' ';
 }
 
+/* Convert a number into a string of octal digits.
+   Convert long VALUE into a DIGITS-digit field at WHERE,
+   including a trailing space.  DIGITS==2 means
+   1 digit, and a space.
+*/
+
+static void
+to_oct_no_nul (value, digits, where)
+     register long value;
+     register int digits;
+     register char *where;
+{
+  to_oct (value, digits + 1, where);
+}
+
 /* Return
    2 if BUF is a valid POSIX tar header (the checksum is correct
    and it has the "ustar" magic string),
>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list