7a3408
From e8ffa273684efa5de18fad0913d6da4a93a9682d Mon Sep 17 00:00:00 2001
7a3408
Message-Id: <e8ffa273684efa5de18fad0913d6da4a93a9682d@dist-git>
7a3408
From: Martin Kletzander <mkletzan@redhat.com>
7a3408
Date: Thu, 13 Aug 2015 15:11:45 +0200
7a3408
Subject: [PATCH] qemu: Fix segfault when parsing private domain data
7a3408
7a3408
https://bugzilla.redhat.com/show_bug.cgi?id=1162947
7a3408
7a3408
When parsing private domain data, there are two paths that are flawed.
7a3408
They are both error paths, just from different parts of the function.
7a3408
One of them can call free() on an uninitialized pointer.  Initialization
7a3408
to NULL is enough here.  The other one is a bit trickier to explain, but
7a3408
as easy as the first one to fix.  We create capabilities, parse them and
7a3408
then assign them into the private data pointer inside the domain object.
7a3408
If, however, we get to fail from now on, the error path calls unrefs the
7a3408
capabilities and then, when the domain object is being cleaned,
7a3408
qemuDomainObjPrivateFree() tries to unref them as well.  That causes a
7a3408
segfault.  Settin the pointer to NULL upon successful addition to the
7a3408
private data is enough.
7a3408
7a3408
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
7a3408
(cherry picked from commit 92ddffdbd3c91d99f8f7ed9b661388a2c5d36cc2)
7a3408
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
7a3408
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
7a3408
---
7a3408
 src/qemu/qemu_domain.c | 3 ++-
7a3408
 1 file changed, 2 insertions(+), 1 deletion(-)
7a3408
7a3408
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
7a3408
index c247737..d95f24f 100644
7a3408
--- a/src/qemu/qemu_domain.c
7a3408
+++ b/src/qemu/qemu_domain.c
7a3408
@@ -627,7 +627,7 @@ qemuDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt,
7a3408
 {
7a3408
     qemuDomainObjPrivatePtr priv = vm->privateData;
7a3408
     char *monitorpath;
7a3408
-    char *tmp;
7a3408
+    char *tmp = NULL;
7a3408
     int n;
7a3408
     size_t i;
7a3408
     xmlNodePtr *nodes = NULL;
7a3408
@@ -715,6 +715,7 @@ qemuDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt,
7a3408
         }
7a3408
 
7a3408
         priv->qemuCaps = qemuCaps;
7a3408
+        qemuCaps = NULL;
7a3408
     }
7a3408
     VIR_FREE(nodes);
7a3408
 
7a3408
-- 
7a3408
2.5.0
7a3408