]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
snapshot: fix snapshot deletion use-after-free
authorEric Blake <eblake@redhat.com>
Tue, 14 Feb 2012 20:08:56 +0000 (13:08 -0700)
committerEric Blake <eblake@redhat.com>
Thu, 16 Feb 2012 00:24:05 +0000 (17:24 -0700)
Bug introduced in commit 35abced.  On an inactive domain,
$ virsh snapshot-create-as dom snap
$ virsh snapshot-create dom
$ virsh snapshot-create dom
$ virsh snapshot-delete --children dom snap
could crash libvirtd, due to a use-after-free that results
when the callback freed the current element in the iteration.

* src/conf/domain_conf.c (virDomainSnapshotForEachChild)
(virDomainSnapshotActOnDescendant): Allow iteration to delete
current child.

src/conf/domain_conf.c

index 9b03b56d0e5952c32a07b84916821b7f1c47aeed..85a20580056d6763df5cc8820b098d3547e67ccb 100644 (file)
@@ -13347,8 +13347,9 @@ virDomainSnapshotForEachChild(virDomainSnapshotObjPtr snapshot,
     virDomainSnapshotObjPtr child = snapshot->first_child;
 
     while (child) {
+        virDomainSnapshotObjPtr next = child->sibling;
         (iter)(child, child->def->name, data);
-        child = child->sibling;
+        child = next;
     }
 
     return snapshot->nchildren;
@@ -13368,10 +13369,10 @@ virDomainSnapshotActOnDescendant(void *payload,
     virDomainSnapshotObjPtr obj = payload;
     struct snapshot_act_on_descendant *curr = data;
 
-    (curr->iter)(payload, name, curr->data);
     curr->number += 1 + virDomainSnapshotForEachDescendant(obj,
                                                            curr->iter,
                                                            curr->data);
+    (curr->iter)(payload, name, curr->data);
 }
 
 /* Run iter(data) on all descendants of snapshot, while ignoring all