]> Dogcows Code - chaz/tar/blobdiff - src/incremen.c
* src/common.h (check_device_option): New global.
[chaz/tar] / src / incremen.c
index acccb8f605753ff9170a9b94479540521bd3d845..d75b844c979b0871c47a13757246a171eb806ac4 100644 (file)
@@ -124,8 +124,8 @@ make_directory (const char *name)
   directory->orig = NULL;
   directory->flags = false;
   strcpy (directory->name, name);
-  if (ISSLASH (directory->name[namelen-1]))
-    directory->name[namelen-1] = 0;
+  if (namelen && ISSLASH (directory->name[namelen - 1]))
+    directory->name[namelen - 1] = 0;
   directory->tagfile = NULL;
   return directory;
 }
@@ -250,7 +250,8 @@ procdir (char *name_buffer, struct stat *stat_data,
         directories, consider all NFS devices as equal,
         relying on the i-node to establish differences.  */
 
-      if (! (((DIR_IS_NFS (directory) & nfs)
+      if (! ((!check_device_option
+             || (DIR_IS_NFS (directory) && nfs)
              || directory->device_number == stat_data->st_dev)
             && directory->inode_number == stat_data->st_ino))
        {
@@ -336,8 +337,7 @@ procdir (char *name_buffer, struct stat *stat_data,
 
   {
     const char *tag_file_name;
-    size_t len;
-    
+
     switch (check_exclusion_tags (name_buffer, &tag_file_name))
       {
       case exclusion_tag_all:
@@ -356,13 +356,13 @@ procdir (char *name_buffer, struct stat *stat_data,
                               _("contents not dumped"));
        directory->children = NO_CHILDREN;
        break;
-       
+
       case exclusion_tag_under:
        exclusion_tag_warning (name_buffer, tag_file_name,
                               _("contents not dumped"));
        directory->tagfile = tag_file_name;
        break;
-       
+
       case exclusion_tag_none:
        break;
       }
@@ -508,7 +508,7 @@ scan_directory (char *dir, dev_t device)
   size_t name_length;          /* used length in name_buffer */
   struct stat stat_data;
   struct directory *directory;
-  
+
   if (! dirp)
     savedir_error (dir);
 
@@ -532,7 +532,7 @@ scan_directory (char *dir, dev_t device)
 
   directory = procdir (name_buffer, &stat_data, device, NO_CHILDREN, false,
                       NULL);
-  
+
   if (dirp && directory->children != NO_CHILDREN)
     {
       char  *entry;    /* directory entry being scanned */
@@ -609,10 +609,17 @@ get_directory_contents (char *dir, dev_t device)
 static void
 obstack_code_rename (struct obstack *stk, char *from, char *to)
 {
+  char *s;
+
+  s = from[0] == 0 ? from :
+                     safer_name_suffix (from, false, absolute_names_option);
   obstack_1grow (stk, 'R');
-  obstack_grow (stk, from, strlen (from) + 1);
+  obstack_grow (stk, s, strlen (s) + 1);
+
+  s = to[0] == 0 ? to:
+                   safer_name_suffix (to, false, absolute_names_option);
   obstack_1grow (stk, 'T');
-  obstack_grow (stk, to, strlen (to) + 1);
+  obstack_grow (stk, s, strlen (s) + 1);
 }
 
 static bool
@@ -1403,6 +1410,19 @@ try_purge_directory (char const *directory_name)
          arc += strlen (arc) + 1;
          dst = arc + 1;
 
+         /* Ensure that neither source nor destination are absolute file
+            names (unless permitted by -P option), and that they do not
+            contain dubious parts (e.g. ../).
+
+            This is an extra safety precaution. Besides, it might be
+            necessary to extract from archives created with tar versions
+            prior to 1.19. */
+
+         if (*src)
+           src = safer_name_suffix (src, false, absolute_names_option);
+         if (*dst)
+           dst = safer_name_suffix (dst, false, absolute_names_option);
+
          if (*src == 0)
            src = temp_stub;
          else if (*dst == 0)
This page took 0.022398 seconds and 4 git commands to generate.