]> Dogcows Code - chaz/tar/blobdiff - src/list.c
(read_header): Accept file names as specified by POSIX.1-1996 section 10.1.1.
[chaz/tar] / src / list.c
index c5fd5f4b2970b423abfb52594ee9ce35531b9464..7a9bd5079b4f0dc5da34fe208e4f7e3034c8f153 100644 (file)
   ((unsigned char) (Char) >= '0' && (unsigned char) (Char) <= '7')
 #define ISSPACE(Char) (ISASCII (Char) && isspace (Char))
 
+#ifndef FNM_LEADING_DIR
+# include <fnmatch.h>
+#endif
+
 #include "common.h"
 
 union block *current_header;   /* points to current archive header */
@@ -62,6 +66,12 @@ read_and (void (*do_something) ())
          /* Valid header.  We should decode next field (mode) first.
             Ensure incoming names are null terminated.  */
 
+         if (ending_file_option &&
+             fnmatch (ending_file_option, current_file_name,
+                      FNM_LEADING_DIR) == 0) {
+           goto all_done;
+         }
+
          /* FIXME: This is a quick kludge before 1.12 goes out.  */
          current_stat.st_mtime = TIME_FROM_OCT (current_header->header.mtime);
 
@@ -164,6 +174,7 @@ read_and (void (*do_something) ())
        }
       break;
     }
+ all_done: ;
 
   apply_delayed_set_stat ();
   close_archive ();
@@ -404,9 +415,28 @@ read_header (void)
        }
       else
        {
-         assign_string (&current_file_name,
-                        (next_long_name ? next_long_name
-                         : current_header->header.name));
+         char *name = next_long_name;
+         struct posix_header *h = &current_header->header;
+         char namebuf[sizeof h->prefix + 1 + sizeof h->name + 1];
+
+         if (! name)
+           {
+             /* Accept file names as specified by POSIX.1-1996
+                 section 10.1.1.  */
+             char *np = namebuf;
+             if (h->prefix[0])
+               {
+                 memcpy (np, h->prefix, sizeof h->prefix);
+                 np[sizeof h->prefix] = '\0';
+                 np += strlen (np);
+                 *np++ = '/';
+               }
+             memcpy (np, h->name, sizeof h->name);
+             np[sizeof h->name] = '\0';
+             name = namebuf;
+           }
+
+         assign_string (&current_file_name, name);
          assign_string (&current_link_name,
                         (next_long_link ? next_long_link
                          : current_header->header.linkname));
This page took 0.023664 seconds and 4 git commands to generate.