[gvfs/gnome-3-18] metadata: Avoid endless recursion when copying meta files



commit 7c20c24de6d803963b96ee39df49e478a933c946
Author: Ondrej Holy <oholy redhat com>
Date:   Thu Dec 10 16:22:39 2015 +0100

    metadata: Avoid endless recursion when copying meta files
    
    meta_builder_copy is traversing the tree while at the same time possibly
    writing to it. This might leads to endless recursion and consequent
    segmentation fault. Do the entire copy into a new MetaFile that is not
    inserted into the source tree and consequently insert the MetaFile once
    the copy is done.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=759341

 metadata/metabuilder.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)
---
diff --git a/metadata/metabuilder.c b/metadata/metabuilder.c
index af9e99d..7c419b8 100644
--- a/metadata/metabuilder.c
+++ b/metadata/metabuilder.c
@@ -298,7 +298,7 @@ meta_builder_copy (MetaBuilder *builder,
                   const char  *dest_path,
                   guint64      mtime)
 {
-  MetaFile *src, *dest;
+  MetaFile *src, *dest, *temp;
 
   meta_builder_remove (builder, dest_path, mtime);
 
@@ -306,9 +306,15 @@ meta_builder_copy (MetaBuilder *builder,
   if (src == NULL)
     return;
 
+  temp = metafile_new (NULL, NULL);
+  meta_file_copy_into (src, temp, mtime);
+
   dest = meta_builder_lookup (builder, dest_path, TRUE);
+  dest->data = temp->data;
+  dest->children = temp->children;
+  dest->last_changed = temp->last_changed;
 
-  meta_file_copy_into (src, dest, mtime);
+  g_free (temp);
 }
 
 void


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]