This patch proposed by a user of my Debian packaging of gzip seems like
a reasonable addition.  Opinions?

Bdale

--- Begin Message ---
Package: gzip
Version: 1.3.12-6
Severity: important
Tags: patch

When gzip is compressing / decompressing regular files, it checks the
return status of close on the outfile. But when compressing / decompressing to
stdout, it doesn't call close before exiting. This can lead to
undetectable write errors on NFS v3 filesystems, where writes can be
buffered locally until the final close or exit triggers an NFS v3 commit.

-- System Information:
Debian Release: 5.0
  APT prefers stable
  APT policy: (500, 'stable')
Architecture: amd64 (x86_64)

Kernel: Linux 2.6.24.2-ls4 (SMP w/2 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=ANSI_X3.4-1968) 
(ignored: LC_ALL set to POSIX)
Shell: /bin/sh linked to /bin/bash

Versions of packages gzip depends on:
ii  debianutils                   2.30       Miscellaneous utilities specific t
ii  libc6                         2.7-18     GNU C Library: Shared libraries

gzip recommends no packages.

Versions of packages gzip suggests:
ii  less                          418-1      Pager program similar to more

-- no debconf information
--- gzip-1.3.12.orig/gzip.c
+++ gzip-1.3.12/gzip.c
@@ -182,6 +182,7 @@
 
 int ascii = 0;        /* convert end-of-lines to local OS conventions */
 int to_stdout = 0;    /* output to stdout (-c) */
+int used_stdout = 0;  /* set to 1 if compressed output ever went to stdout */
 int decompress = 0;   /* decompress (-d) */
 int force = 0;        /* don't ask questions, compress links (-f) */
 int no_name = -1;     /* don't save or restore the original file name */
@@ -582,6 +583,13 @@
     if (list && !quiet && file_count > 1) {
 	do_list(-1, -1); /* print totals */
     }
+
+    /* if compressed data ever written to stdout,
+     * check for write errors that show up in close (NFS) */
+    if ((used_stdout || to_stdout) && fclose(stdout) != 0) {
+        write_error();
+    }
+
     do_exit(exit_code);
     return exit_code; /* just to avoid lint warning */
 }
@@ -654,6 +662,7 @@
 
     clear_bufs(); /* clear input and output buffers */
     to_stdout = 1;
+    used_stdout = 1;
     part_nb = 0;
 
     if (decompress) {

--- End Message ---

Reply via email to