[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Fwd: Bug#538187: gzip doesn't call close() when writing to stdout]
From: |
Jim Meyering |
Subject: |
Re: [Fwd: Bug#538187: gzip doesn't call close() when writing to stdout] |
Date: |
Wed, 29 Jul 2009 17:49:53 +0200 |
Bdale Garbee wrote:
> This patch proposed by a user of my Debian packaging of gzip seems like
> a reasonable addition. Opinions?
Good catch.
However, there are many exit points, not just that one
at the end of main. This patch ensures that no matter
which one is taken, that close is performed and checked.
It also uses gnulib's closein module so that it also closes
stdin, just as programs like cp and rm do, since they
too may prompt the user.
Here's a better patch:
2009-07-29 Jim Meyering <address@hidden>
avoid silent data loss e.g., on NFS, due to unchecked close of stdout
* gzip.c: Include "closein.h".
(main): Use atexit (close_stdin);
* bootstrap.conf (gnulib_modules): Add closein.
Prompted by Mark Kidwell's report and patch in
http://bugs.debian.org/538187
Index: gzip.c
===================================================================
RCS file: /sources/gzip/gzip/gzip.c,v
retrieving revision 1.21
diff -u -p -r1.21 gzip.c
--- gzip.c 25 Nov 2007 17:19:46 -0000 1.21
+++ gzip.c 29 Jul 2009 15:34:53 -0000
@@ -1,6 +1,6 @@
/* gzip (GNU zip) -- compress files with zip algorithm and 'compress' interface
- Copyright (C) 1999, 2001, 2002, 2006, 2007 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2001, 2002, 2006, 2007, 2009 Free Software Foundation,
Inc.
Copyright (C) 1992-1993 Jean-loup Gailly
This program is free software; you can redistribute it and/or modify
@@ -64,6 +64,7 @@ static char rcsid[] = "$Id: gzip.c,v 1.2
#include <sys/stat.h>
#include <errno.h>
+#include "closein.h"
#include "tailor.h"
#include "gzip.h"
#include "lzw.h"
@@ -417,6 +418,8 @@ int main (argc, argv)
program_name = gzip_base_name (argv[0]);
proglen = strlen (program_name);
+ atexit (close_stdin);
+
/* Suppress .exe for MSDOS, OS/2 and VMS: */
if (4 < proglen && strequ (program_name + proglen - 4, ".exe"))
program_name[proglen - 4] = '\0';
Index: bootstrap.conf
===================================================================
RCS file: /sources/gzip/gzip/bootstrap.conf,v
retrieving revision 1.6
diff -u -p -r1.6 bootstrap.conf
--- bootstrap.conf 3 Jul 2007 20:37:07 -0000 1.6
+++ bootstrap.conf 29 Jul 2009 15:34:53 -0000
@@ -1,6 +1,6 @@
# Bootstrap configuration.
-# Copyright (C) 2006 Free Software Foundation, Inc.
+# Copyright (C) 2006, 2009 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -23,6 +23,7 @@ IMPORT_FROM_GETTEXT=no
# gnulib modules used by this package.
gnulib_modules='
+ closein
fcntl
fcntl-safer
fdl