From f839c18b279bbcb079c6738e3781351f51107c23 Mon Sep 17 00:00:00 2001 From: Ondrej Holy Date: Thu, 10 Dec 2015 16:22:39 +0100 Subject: 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 file changed, 8 insertions(+), 2 deletions(-) diff --git a/metadata/metabuilder.c b/metadata/metabuilder.c index af9e99da..7c419b83 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 -- cgit v1.2.1