]> Dogcows Code - chaz/tar/blobdiff - src/tar.c
Carefully crafted invalid headers can cause buffer overrun.
[chaz/tar] / src / tar.c
index a5b1393f4433ca7a8d26ead5980b816e7f0b555f..b0e039dbc7ff28d6970103fd4d5dabd9801d09db 100644 (file)
--- a/src/tar.c
+++ b/src/tar.c
@@ -17,7 +17,7 @@
 
    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
-   59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
 
 #include <system.h>
 
@@ -634,14 +634,24 @@ for complete list of authors.\n"));
     "   GNU General Public License for more details.\n"
     "\n"
     "   You should have received a copy of the GNU General Public License\n"
-    "   along with GNU tar; if not, write to the Free Software\n"
-    "   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA\n\n"));
+    "   along with GNU tar; if not, write to the Free Software Foundation,\n"
+    "   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA\n\n"));
   exit (0);
 }
 
 static volatile int _argp_hang;
 
-static bool
+enum read_file_list_state  /* Result of reading file name from the list file */
+  {
+    file_list_success,     /* OK, name read successfully */
+    file_list_end,         /* End of list file */
+    file_list_zero         /* Zero separator encountered where it should not */
+  };
+
+/* Read from FP a sequence of characters up to FILENAME_TERMINATOR and put them
+   into STK.
+ */
+static enum read_file_list_state
 read_name_from_file (FILE *fp, struct obstack *stk)
 {
   int c;
@@ -650,14 +660,18 @@ read_name_from_file (FILE *fp, struct obstack *stk)
   for (c = getc (fp); c != EOF && c != filename_terminator; c = getc (fp))
     {
       if (c == 0)
-       FATAL_ERROR((0, 0, N_("file name contains null character")));
+       {
+         /* We have read a zero separator. The file possibly is zero-separated */
+         /* FATAL_ERROR((0, 0, N_("file name contains null character"))); */
+         return file_list_zero;
+       }
       obstack_1grow (stk, c);
       counter++;
     }
 
   obstack_1grow (stk, 0);
 
-  return !(counter == 0 && c == EOF);
+  return (counter == 0 && c == EOF) ? file_list_end : file_list_success;
 }
 
 \f
@@ -706,6 +720,7 @@ update_argv (const char *filename, struct argp_state *state)
   char **new_argv;
   size_t new_argc;
   bool is_stdin = false;
+  enum read_file_list_state read_state;
 
   if (!strcmp (filename, "-"))
     {
@@ -720,9 +735,33 @@ update_argv (const char *filename, struct argp_state *state)
        open_fatal (filename);
     }
 
-  while (read_name_from_file (fp, &argv_stk))
+  while ((read_state = read_name_from_file (fp, &argv_stk)) == file_list_success)
     count++;
 
+  if (read_state == file_list_zero)
+    {
+      size_t size;
+
+      WARN ((0, 0, N_("%s: file name read contains nul character"),
+            quotearg_colon (filename)));
+
+      /* Prepare new stack contents */
+      size = obstack_object_size (&argv_stk);
+      p = obstack_finish (&argv_stk);
+      for (; size > 0; size--, p++)
+       if (*p)
+         obstack_1grow (&argv_stk, *p);
+        else
+         obstack_1grow (&argv_stk, '\n');
+      obstack_1grow (&argv_stk, 0);
+      count = 1;
+
+      /* Read rest of files using new filename terminator */
+      filename_terminator = 0;
+      while (read_name_from_file (fp, &argv_stk) == file_list_success)
+       count++;
+    }
+
   if (!is_stdin)
     fclose (fp);
 
@@ -934,15 +973,14 @@ parse_opt (int key, char *arg, struct argp_state *state)
              stat_error (arg);
              USAGE_ERROR ((0, 0, _("Date sample file not found")));
            }
-         newer_mtime_option.tv_sec = st.st_mtime;
-         newer_mtime_option.tv_nsec = TIMESPEC_NS (st.st_mtim);
+         newer_mtime_option = get_stat_mtime (&st);
        }
       else
        {
          if (! get_date (&newer_mtime_option, arg, NULL))
            {
              WARN ((0, 0, _("Substituting %s for unknown date format %s"),
-                    tartime (newer_mtime_option.tv_sec), quote (arg)));
+                    tartime (newer_mtime_option, false), quote (arg)));
              newer_mtime_option.tv_nsec = 0;
            }
          else
@@ -1780,16 +1818,10 @@ decode_options (int argc, char **argv)
 
   if (verbose_option && args.textual_date_option)
     {
-      /* FIXME: tartime should support nanoseconds, too, so that this
-        comparison doesn't complain about lost nanoseconds.  */
-      char const *treated_as = tartime (newer_mtime_option.tv_sec);
+      char const *treated_as = tartime (newer_mtime_option, true);
       if (strcmp (args.textual_date_option, treated_as) != 0)
-       WARN ((0, 0,
-              ngettext ("Treating date `%s' as %s + %ld nanosecond",
-                        "Treating date `%s' as %s + %ld nanoseconds",
-                        newer_mtime_option.tv_nsec),
-              args.textual_date_option, treated_as,
-              newer_mtime_option.tv_nsec));
+       WARN ((0, 0, _("Treating date `%s' as %s"),
+              args.textual_date_option, treated_as));
     }
 }
 
This page took 0.024386 seconds and 4 git commands to generate.