]> Dogcows Code - chaz/tar/blobdiff - src/tar.c
tar: more reliable directory traversal when creating archives
[chaz/tar] / src / tar.c
index 10ba8a9b8a06bf2a9709008e6bf9a3d8d731f7bf..ab53cec684295d6c80f492dbd89de09bdf5f83fa 100644 (file)
--- a/src/tar.c
+++ b/src/tar.c
@@ -74,7 +74,7 @@
 static const char *stdin_used_by;
 
 /* Doesn't return if stdin already requested.  */
-void
+static void
 request_stdin (const char *option)
 {
   if (stdin_used_by)
@@ -1509,7 +1509,7 @@ parse_opt (int key, char *arg, struct argp_state *state)
       {
        uintmax_t u;
        char *p;
-       
+
        if (xstrtoumax (arg, &p, 10, &u, TAR_SIZE_SUFFIXES) != LONGINT_OK)
          USAGE_ERROR ((0, 0, "%s: %s", quotearg_colon (arg),
                        _("Invalid tape length")));
@@ -1968,7 +1968,7 @@ parse_opt (int key, char *arg, struct argp_state *state)
     case RECORD_SIZE_OPTION:
       {
        uintmax_t u;
-       
+
        if (! (xstrtoumax (arg, NULL, 10, &u, TAR_SIZE_SUFFIXES) == LONGINT_OK
               && u == (size_t) u))
          USAGE_ERROR ((0, 0, "%s: %s", quotearg_colon (arg),
@@ -2465,6 +2465,14 @@ decode_options (int argc, char **argv)
   if (recursive_unlink_option)
     old_files_option = UNLINK_FIRST_OLD_FILES;
 
+  /* Flags for accessing files to be copied into.  POSIX says
+     O_NONBLOCK has unspecified effect on most types of files, but in
+     practice it never harms and sometimes helps.  */
+  open_read_flags =
+    (O_RDONLY | O_BINARY | O_NOCTTY | O_NONBLOCK
+     | (dereference_option ? 0 : O_NOFOLLOW)
+     | (atime_preserve_option == system_atime_preserve ? O_NOATIME : 0));
+  fstatat_flags = dereference_option ? 0 : AT_SYMLINK_NOFOLLOW;
 
   if (subcommand_option == TEST_LABEL_SUBCOMMAND)
     {
@@ -2494,8 +2502,8 @@ decode_options (int argc, char **argv)
                      _("Cowardly refusing to create an empty archive")));
       if (args.compress_autodetect && archive_names
          && strcmp (archive_name_array[0], "-"))
-       set_comression_program_by_suffix (archive_name_array[0],
-                                         use_compress_program_option);
+       set_compression_program_by_suffix (archive_name_array[0],
+                                          use_compress_program_option);
       break;
 
     case EXTRACT_SUBCOMMAND:
@@ -2686,6 +2694,8 @@ tar_stat_destroy (struct tar_stat_info *st)
   free (st->gname);
   free (st->sparse_map);
   free (st->dumpdir);
+  if (0 < st->fd)
+    close (st->fd);
   xheader_destroy (&st->xhdr);
   memset (st, 0, sizeof (*st));
 }
This page took 0.026137 seconds and 4 git commands to generate.