From thomas@cuivre.fr.eu.org  Tue Jun  1 10:01:18 2010
Return-Path: <thomas@cuivre.fr.eu.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 3D16F1065677
	for <FreeBSD-gnats-submit@freebsd.org>; Tue,  1 Jun 2010 10:01:18 +0000 (UTC)
	(envelope-from thomas@cuivre.fr.eu.org)
Received: from melamine.cuivre.fr.eu.org (unknown [IPv6:2001:470:1f15:1531:224:e8ff:fe3d:60a5])
	by mx1.freebsd.org (Postfix) with ESMTP id 009418FC22
	for <FreeBSD-gnats-submit@freebsd.org>; Tue,  1 Jun 2010 10:01:17 +0000 (UTC)
Received: by melamine.cuivre.fr.eu.org (Postfix, from userid 1000)
	id 436725E26; Tue,  1 Jun 2010 12:01:17 +0200 (CEST)
Message-Id: <20100601100117.436725E26@melamine.cuivre.fr.eu.org>
Date: Tue,  1 Jun 2010 12:01:17 +0200 (CEST)
From: Thomas Quinot <thomas@cuivre.fr.eu.org>
Reply-To: Thomas Quinot <thomas@cuivre.fr.eu.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: gzip -c <file> does not save original time stamp
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         147275
>Category:       bin
>Synopsis:       [patch] gzip(1): gzip -c <file> does not save original time stamp
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    delphij
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Jun 01 10:10:02 UTC 2010
>Closed-Date:    Sat Jun 12 05:39:37 UTC 2010
>Last-Modified:  Sat Jun 12 05:39:37 UTC 2010
>Originator:     Thomas Quinot
>Release:        FreeBSD 8.0-STABLE amd64
>Organization:
>Environment:
System: FreeBSD melamine.cuivre.fr.eu.org 8.0-STABLE FreeBSD 8.0-STABLE #0: Sun Mar 28 14:46:11 CEST 2010 thomas@melamine.cuivre.fr.eu.org:/usr/obj/usr/src/sys/GENERIC amd64


	
>Description:
	When a file name is provided on the command line, gzip -c does not
	save its timestamp in the output compressed stream.
>How-To-Repeat:
	cd /tmp
	touch foo
	gzip -c foo > foo1.gz
	gzip foo
	file foo1.gz foo.gz

foo1.gz: gzip compressed data, was "foo", from Unix
foo.gz:  gzip compressed data, was "foo", from Unix, last modified: Tue Jun  1 11:55:30 2010

>Fix:

Index: gzip.c
===================================================================
--- gzip.c	(rvision 208689)
+++ gzip.c	(copie de travail)
@@ -1212,6 +1212,7 @@
 {
 	int in;
 	int out;
+	int rc;
 	off_t size, insize;
 #ifndef SMALL
 	struct stat isb, osb;
@@ -1224,9 +1225,16 @@
 		return -1;
 	}
 
+	/* Stat input file even in stdout (-c) mode so that the
+	 * correct time stamp is inserted in the compressed
+	 * output stream.
+	 */
+
+	rc = fstat (in, &isb);
+
 	if (cflag == 0) {
 #ifndef SMALL
-		if (fstat(in, &isb) == 0) {
+		if (rc == 0) {
 			if (isb.st_nlink > 1 && fflag == 0) {
 				maybe_warnx("%s has %d other link%s -- "
 					    "skipping", file, isb.st_nlink - 1,


>Release-Note:
>Audit-Trail:

From: Jilles Tjoelker <jilles@stack.nl>
To: bug-followup@FreeBSD.org, thomas@cuivre.fr.eu.org
Cc:  
Subject: Re: bin/147275: [patch] gzip(1): gzip -c &lt;file&gt; does not
 save original time stamp
Date: Sat, 5 Jun 2010 21:49:53 +0200

 I'm not sure if we care, but this patch breaks compilation with SMALL
 defined (if it is not already broken, as SMALL does not appear to be
 used).
 
 -- 
 Jilles Tjoelker
Responsible-Changed-From-To: freebsd-bugs->delphij 
Responsible-Changed-By: delphij 
Responsible-Changed-When: Mon Jun 7 09:11:42 UTC 2010 
Responsible-Changed-Why:  
Take. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=147275 

From: Thomas Quinot <thomas@FreeBSD.ORG>
To: delphij@FreeBSD.org
Cc: bug-followup@FreeBSD.org
Subject: Re: bin/147275: [patch] gzip(1): gzip -c <file> does not save
 original time stamp
Date: Mon, 7 Jun 2010 11:16:08 +0200

 * delphij@FreeBSD.org, 2010-06-07 :
 
 > Responsible-Changed-From-To: freebsd-bugs->delphij
 > Responsible-Changed-By: delphij
 > Responsible-Changed-When: Mon Jun 7 09:11:42 UTC 2010
 > Responsible-Changed-Why: 
 > Take.
 
 Thanks! Let me know if there's any further info I can provide.
 
 Thomas.
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/147275: commit references a PR
Date: Mon,  7 Jun 2010 10:09:51 +0000 (UTC)

 Author: delphij
 Date: Mon Jun  7 10:09:40 2010
 New Revision: 208888
 URL: http://svn.freebsd.org/changeset/base/208888
 
 Log:
   Correct a bug in gzip(1): make sure that initialize isb with fstat() on
   input file before using it.
   
   PR:		bin/147275
   Submitted by:	thomas
   MFC after:	1 week
 
 Modified:
   head/usr.bin/gzip/gzip.c
 
 Modified: head/usr.bin/gzip/gzip.c
 ==============================================================================
 --- head/usr.bin/gzip/gzip.c	Mon Jun  7 08:23:16 2010	(r208887)
 +++ head/usr.bin/gzip/gzip.c	Mon Jun  7 10:09:40 2010	(r208888)
 @@ -1224,17 +1224,23 @@ file_compress(char *file, char *outfile,
  		return -1;
  	}
  
 +#ifndef SMALL
 +	if (fstat(in, &isb) != 0) {
 +		maybe_warn("couldn't stat: %s", file);
 +		close(in);
 +		return -1;
 +	}
 +#endif
 +
  	if (cflag == 0) {
  #ifndef SMALL
 -		if (fstat(in, &isb) == 0) {
 -			if (isb.st_nlink > 1 && fflag == 0) {
 +		if (isb.st_nlink != 1 && fflag == 0) {
  				maybe_warnx("%s has %d other link%s -- "
  					    "skipping", file, isb.st_nlink - 1,
  					    isb.st_nlink == 1 ? "" : "s");
  				close(in);
  				return -1;
  			}
 -		}
  
  		if (fflag == 0 && (suff = check_suffix(file, 0))
  		    && suff->zipped[0] != 0) {
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->patched 
State-Changed-By: delphij 
State-Changed-When: Mon Jun 7 10:10:53 UTC 2010 
State-Changed-Why:  
Fixed in -CURRENT, MFC reminder. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=147275 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/147275: commit references a PR
Date: Sat, 12 Jun 2010 05:23:14 +0000 (UTC)

 Author: delphij
 Date: Sat Jun 12 05:22:55 2010
 New Revision: 209090
 URL: http://svn.freebsd.org/changeset/base/209090
 
 Log:
   MFC r208888,208889,209017:
   
    - make sure that initialize isb with fstat() on
      input file before using it. (bin/147275)
    - Fix grammar for st_nlink.
    - Style changes.
   
   PR:		bin/147275
   Approved by:	re (kensmith)
 
 Modified:
   stable/8/usr.bin/gzip/gzip.c
 Directory Properties:
   stable/8/usr.bin/gzip/   (props changed)
 
 Modified: stable/8/usr.bin/gzip/gzip.c
 ==============================================================================
 --- stable/8/usr.bin/gzip/gzip.c	Sat Jun 12 05:21:29 2010	(r209089)
 +++ stable/8/usr.bin/gzip/gzip.c	Sat Jun 12 05:22:55 2010	(r209090)
 @@ -65,10 +65,6 @@ __RCSID("$FreeBSD$");
  #include <getopt.h>
  #include <time.h>
  
 -#ifndef PRIdOFF
 -#define PRIdOFF PRId64
 -#endif
 -
  /* what type of file are we dealing with */
  enum filetype {
  	FT_GZIP,
 @@ -1221,40 +1217,46 @@ file_compress(char *file, char *outfile,
  	in = open(file, O_RDONLY);
  	if (in == -1) {
  		maybe_warn("can't open %s", file);
 -		return -1;
 +		return (-1);
  	}
  
 +#ifndef SMALL
 +	if (fstat(in, &isb) != 0) {
 +		maybe_warn("couldn't stat: %s", file);
 +		close(in);
 +		return (-1);
 +	}
 +#endif
 +
  	if (cflag == 0) {
  #ifndef SMALL
 -		if (fstat(in, &isb) == 0) {
 -			if (isb.st_nlink > 1 && fflag == 0) {
 -				maybe_warnx("%s has %d other link%s -- "
 -					    "skipping", file, isb.st_nlink - 1,
 -					    isb.st_nlink == 1 ? "" : "s");
 -				close(in);
 -				return -1;
 -			}
 +		if (isb.st_nlink > 1 && fflag == 0) {
 +			maybe_warnx("%s has %d other link%s -- skipping",
 +			    file, isb.st_nlink - 1,
 +			    (isb.st_nlink - 1) == 1 ? "" : "s");
 +			close(in);
 +			return (-1);
  		}
  
 -		if (fflag == 0 && (suff = check_suffix(file, 0))
 -		    && suff->zipped[0] != 0) {
 +		if (fflag == 0 && (suff = check_suffix(file, 0)) &&
 +		    suff->zipped[0] != 0) {
  			maybe_warnx("%s already has %s suffix -- unchanged",
 -				    file, suff->zipped);
 +			    file, suff->zipped);
  			close(in);
 -			return -1;
 +			return (-1);
  		}
  #endif
  
  		/* Add (usually) .gz to filename */
  		if ((size_t)snprintf(outfile, outsize, "%s%s",
 -					file, suffixes[0].zipped) >= outsize)
 +		    file, suffixes[0].zipped) >= outsize)
  			memcpy(outfile + outsize - suffixes[0].ziplen - 1,
 -				suffixes[0].zipped, suffixes[0].ziplen + 1);
 +			    suffixes[0].zipped, suffixes[0].ziplen + 1);
  
  #ifndef SMALL
  		if (check_outfile(outfile) == 0) {
  			close(in);
 -			return -1;
 +			return (-1);
  		}
  #endif
  	}
 @@ -1264,7 +1266,7 @@ file_compress(char *file, char *outfile,
  		if (out == -1) {
  			maybe_warn("could not create output: %s", outfile);
  			fclose(stdin);
 -			return -1;
 +			return (-1);
  		}
  #ifndef SMALL
  		remove_file = outfile;
 @@ -1284,7 +1286,7 @@ file_compress(char *file, char *outfile,
  	 * has the expected size.
  	 */
  	if (cflag != 0)
 -		return insize == -1 ? -1 : size;
 +		return (insize == -1 ? -1 : size);
  
  #ifndef SMALL
  	if (fstat(out, &osb) != 0) {
 @@ -1293,9 +1295,8 @@ file_compress(char *file, char *outfile,
  	}
  
  	if (osb.st_size != size) {
 -		maybe_warnx("output file: %s wrong size (%" PRIdOFF
 -				" != %" PRIdOFF "), deleting",
 -				outfile, osb.st_size, size);
 +		maybe_warnx("output file: %s wrong size (%ju != %ju), deleting",
 +		    outfile, (uintmax_t)osb.st_size, (uintmax_t)size);
  		goto bad_outfile;
  	}
  
 @@ -1307,7 +1308,7 @@ file_compress(char *file, char *outfile,
  
  	/* output is good, ok to delete input */
  	unlink_input(file, &isb);
 -	return size;
 +	return (size);
  
  #ifndef SMALL
      bad_outfile:
 @@ -1316,7 +1317,7 @@ file_compress(char *file, char *outfile,
  
  	maybe_warnx("leaving original %s", file);
  	unlink(outfile);
 -	return size;
 +	return (size);
  #endif
  }
  
 @@ -1564,9 +1565,8 @@ file_uncompress(char *file, char *outfil
  		return -1;
  	}
  	if (osb.st_size != size) {
 -		maybe_warnx("stat gave different size: %" PRIdOFF
 -				" != %" PRIdOFF " (leaving original)",
 -				size, osb.st_size);
 +		maybe_warnx("stat gave different size: %ju != %ju (leaving original)",
 +		    (uintmax_t)size, (uintmax_t)osb.st_size);
  		close(ofd);
  		unlink(outfile);
  		return -1;
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: delphij 
State-Changed-When: Sat Jun 12 05:39:18 UTC 2010 
State-Changed-Why:  
MFC'ed to 8.1-PRERELEASE. 

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