* NEWS: Describe the following change briefly.
authorPaul Eggert <eggert@cs.ucla.edu>
Tue, 5 Dec 2006 07:45:00 +0000 (07:45 +0000)
committerPaul Eggert <eggert@cs.ucla.edu>
Tue, 5 Dec 2006 07:45:00 +0000 (07:45 +0000)
* bootstrap.conf (gnulib_modules): Remove stat-macros; no longer
needed.
* gzip.c: Don't include stat-macros.h; no longer needed.
(treat_file): Refuse to compress files that are setuid, or setgid,
as this can in theory lead to security holes.  Also, refuse to
compress files with the sticky bit set, on general principle.
(copy_stat): Don't copy the setuid, setgid, or sticky bits,
as (given the above change) they'll always be zero here.
Invoke chmod before chown, to close a race condition.

ChangeLog
NEWS
bootstrap.conf
gzip.c

index 8b43fa96cdc9f7c5087d283cba5b84839dc2ef8a..cde2dc58e9cc9b752b284d8273991f1ad0c8d007 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
 2006-12-04  Paul Eggert  <eggert@cs.ucla.edu>
 
+       * NEWS: Describe the following change briefly.
+       * bootstrap.conf (gnulib_modules): Remove stat-macros; no longer
+       needed.
+       * gzip.c: Don't include stat-macros.h; no longer needed.
+       (treat_file): Refuse to compress files that are setuid, or setgid,
+       as this can in theory lead to security holes.  Also, refuse to
+       compress files with the sticky bit set, on general principle.
+       (copy_stat): Don't copy the setuid, setgid, or sticky bits,
+       as (given the above change) they'll always be zero here.
+       Invoke chmod before chown, to close a race condition.
+
        * .cvsignore: Add *.doc, build-aux.
        * doc/.cvignore: New file.
        * lib/.cvsignore: New file.
diff --git a/NEWS b/NEWS
index 0e2c01f294562d60c88a9d9734d70d471247afc1..a899a11faa2e562a318aa7444a77fbb0be01bb40 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,9 @@
 Major changes in Gzip 1.3.7 (not yet released)
 
+* Fix some gzip problems:
+  - Refuse to compress setuid or setgid files, or files with the sticky bit.
+  - Fix more race conditions in setting file permissions and owner.
+  - Fix a core dump caused by a stray abort mistakenly introduced in 1.3.6.
 * Fix some gzexe problems:
   - Improve resistance to denial-of-service attacks.
   - Fix some quoting and escaping bugs.
index 17eff24457401eed355bd312542765a30221fa64..45ceb0b060dcc0aa5ad4a05b1a603d7f29f5c4d1 100644 (file)
@@ -28,7 +28,6 @@ gnulib_modules='
        fcntl-safer
        fdl
        getopt
-       stat-macros
        stat-time
        sys_stat
        utimens
diff --git a/gzip.c b/gzip.c
index a9016a29a7a41ad4002c5c11326c6a66a355ea9c..f732278f082f52acb0ed08c70b9d36ebf198a3f1 100644 (file)
--- a/gzip.c
+++ b/gzip.c
@@ -72,7 +72,6 @@ static char rcsid[] = "$Id$";
 #include "fcntl-safer.h"
 #include "getopt.h"
 #include "openat.h"
-#include "stat-macros.h"
 #include "stat-time.h"
 
                /* configuration */
@@ -716,6 +715,29 @@ local void treat_file(iname)
        close (ifd);
        return;
     }
+
+    if (istat.st_mode & S_ISUID)
+      {
+       WARN ((stderr, "%s: %s is set-user-ID on execution - ignored\n",
+              program_name, ifname));
+       close (ifd);
+       return;
+      }
+    if (istat.st_mode & S_ISGID)
+      {
+       WARN ((stderr, "%s: %s is set-group-ID on execution - ignored\n",
+              program_name, ifname));
+       close (ifd);
+       return;
+      }
+    if (istat.st_mode & S_ISVTX)
+      {
+       WARN ((stderr, "%s: %s has the sticky bit set - file ignored\n",
+              program_name, ifname));
+       close (ifd);
+       return;
+      }
+
     if (istat.st_nlink > 1 && !to_stdout && !force) {
        WARN((stderr, "%s: %s has %lu other link%c -- unchanged\n",
              program_name, ifname, (unsigned long) istat.st_nlink - 1,
@@ -1669,7 +1691,7 @@ local int check_ofname()
 local void copy_stat(ifstat)
     struct stat *ifstat;
 {
-    mode_t mode = ifstat->st_mode & CHMOD_MODE_BITS;
+    mode_t mode = ifstat->st_mode & S_IRWXUGO;
     int r;
 
 #ifndef NO_UTIME
@@ -1698,6 +1720,15 @@ local void copy_stat(ifstat)
          }
       }
 #endif
+
+#ifndef NO_CHOWN
+# if HAVE_FCHOWN
+    fchown (ofd, ifstat->st_uid, ifstat->st_gid);  /* Copy ownership */
+# else
+    chown(ofname, ifstat->st_uid, ifstat->st_gid);  /* Copy ownership */
+# endif
+#endif
+
     /* Copy the protection modes */
 #if HAVE_FCHMOD
     r = fchmod (ofd, mode);
@@ -1712,13 +1743,6 @@ local void copy_stat(ifstat)
            perror(ofname);
        }
     }
-#ifndef NO_CHOWN
-# if HAVE_FCHOWN
-    fchown (ofd, ifstat->st_uid, ifstat->st_gid);  /* Copy ownership */
-# else
-    chown(ofname, ifstat->st_uid, ifstat->st_gid);  /* Copy ownership */
-# endif
-#endif
 }
 
 #if ! NO_DIR