From naddy@mips.inka.de  Mon May 10 13:07:21 2004
Return-Path: <naddy@mips.inka.de>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 241C016A4CE
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 10 May 2004 13:07:21 -0700 (PDT)
Received: from mail-in-03.arcor-online.net (mail-in-03.arcor-online.net [151.189.21.43])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 5B67E43D60
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 10 May 2004 13:07:19 -0700 (PDT)
	(envelope-from naddy@mips.inka.de)
Received: from kemoauc.mips.inka.de (dsl-213-023-058-027.arcor-ip.net [213.23.58.27])
	by mail-in-03.arcor-online.net (Postfix) with ESMTP id D8FC7C2EBF1
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 10 May 2004 22:07:17 +0200 (CEST)
Received: from kemoauc.mips.inka.de (localhost [127.0.0.1])
	by kemoauc.mips.inka.de (8.12.11/8.12.10) with ESMTP id i4AK7H4m057643
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 10 May 2004 22:07:17 +0200 (CEST)
	(envelope-from naddy@kemoauc.mips.inka.de)
Received: (from naddy@localhost)
	by kemoauc.mips.inka.de (8.12.11/8.12.11/Submit) id i4AK7GrL057642;
	Mon, 10 May 2004 22:07:16 +0200 (CEST)
	(envelope-from naddy)
Message-Id: <200405102007.i4AK7GrL057642@kemoauc.mips.inka.de>
Date: Mon, 10 May 2004 22:07:16 +0200 (CEST)
From: Christian Weisgerber <naddy@freebsd.org>
Reply-To: Christian Weisgerber <naddy@freebsd.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: cpio -o -Hustar creates broken timestamps
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         66492
>Category:       bin
>Synopsis:       cpio -o -Hustar creates broken timestamps
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon May 10 13:10:14 PDT 2004
>Closed-Date:    Sat Feb 09 13:12:32 UTC 2008
>Last-Modified:  Sat Feb 09 13:12:32 UTC 2008
>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@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@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:

From: Tim Kientzle <kientzle@freebsd.org>
To: freebsd-gnats-submit@freebsd.org, naddy@freebsd.org,
	obrien@freebsd.org
Cc:  
Subject: Re: bin/66492: cpio -o -Hustar creates broken timestamps
Date: Sat, 07 Aug 2004 11:07:00 -0700

 I've looked at this patch and it looks right to me.
 (And having spent much of the last year researching tar formats,
 I think my opinion might be worth something here. ;-)
 
 While we're in here, we should also fix to_oct to pad
 values with leading zeros (as POSIX requires) rather
 than leading spaces (as was common for pre-POSIX tar
 implementations).
 
 On the other hand, I doubt a lot of people use cpio
 to read/write tar archives, this is on the vendor branch,
 and it hasn't been touched in nearly seven years.
 
 David:  I note that you did the last import of this and
 probably know more about vendor imports than anyone else
 around.  Is this worth fixing?  If you think so, let me know
 and I'll take care of it.
 
 Tim
 
State-Changed-From-To: open->patched 
State-Changed-By: tjr 
State-Changed-When: Sat Oct 1 10:47:26 GMT 2005 
State-Changed-Why:  
Fixed in -current. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=66492 
State-Changed-From-To: patched->closed 
State-Changed-By: remko 
State-Changed-When: Sat Feb 9 13:12:30 UTC 2008 
State-Changed-Why:  
This needs MFC to RELENG_5, though I would like people facing this to 
encourage them to use FreeBSD-6 and/or FreeBSD-7 (preferred) since in 
the not too long future REL_5 will no longer be supported. Close the 
ticket for those reasons 

http://www.freebsd.org/cgi/query-pr.cgi?pr=66492 
>Unformatted:
