render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
3e5111
From 096f83e7910c2c8553044d27918955b278e5ab8d Mon Sep 17 00:00:00 2001
3e5111
Message-Id: <096f83e7910c2c8553044d27918955b278e5ab8d@dist-git>
3e5111
From: Erik Skultety <eskultet@redhat.com>
3e5111
Date: Wed, 7 Jun 2017 14:29:29 +0200
3e5111
Subject: [PATCH] qemu: Fix serial stub console allocation
3e5111
3e5111
When adding the aliased serial stub console, the structure wasn't
3e5111
properly allocated (VIR_ALLOC instead of virDomainChrDefNew) which then
3e5111
resulted in SIGSEGV in virDomainChrSourceIsEqual during a serial device
3e5111
coldplug.
3e5111
3e5111
https://bugzilla.redhat.com/show_bug.cgi?id=1434278
3e5111
3e5111
Signed-off-by: Erik Skultety <eskultet@redhat.com>
3e5111
(cherry picked from commit ff6e94de60b081ae7e9d304e38c63346828c5dbe)
3e5111
Signed-off-by: Erik Skultety <eskultet@redhat.com>
3e5111
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
3e5111
---
3e5111
 src/qemu/qemu_hotplug.c | 12 +++++++-----
3e5111
 1 file changed, 7 insertions(+), 5 deletions(-)
3e5111
3e5111
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
3e5111
index cdeb0617a7..094a5644e0 100644
3e5111
--- a/src/qemu/qemu_hotplug.c
3e5111
+++ b/src/qemu/qemu_hotplug.c
3e5111
@@ -1802,15 +1802,17 @@ qemuDomainChrPreInsert(virDomainDefPtr vmdef,
3e5111
     if (virDomainChrPreAlloc(vmdef, chr) < 0)
3e5111
         return -1;
3e5111
 
3e5111
-    /* Due to some crazy backcompat stuff, the first serial device is an alias
3e5111
-     * to the first console too. If this is the case, the definition must be
3e5111
-     * duplicated as first console device. */
3e5111
+    /* Due to historical reasons, the first console is an alias to the
3e5111
+     * first serial device (if such exists). If this is the case, we need to
3e5111
+     * create an object for the first console as well.
3e5111
+     */
3e5111
     if (vmdef->nserials == 0 && vmdef->nconsoles == 0 &&
3e5111
         chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL) {
3e5111
         if (!vmdef->consoles && VIR_ALLOC(vmdef->consoles) < 0)
3e5111
             return -1;
3e5111
 
3e5111
-        if (VIR_ALLOC(vmdef->consoles[0]) < 0) {
3e5111
+        /* We'll be dealing with serials[0] directly, so NULL is fine here. */
3e5111
+        if (!(vmdef->consoles[0] = virDomainChrDefNew(NULL))) {
3e5111
             VIR_FREE(vmdef->consoles);
3e5111
             return -1;
3e5111
         }
3e5111
@@ -1841,7 +1843,7 @@ qemuDomainChrInsertPreAllocCleanup(virDomainDefPtr vmdef,
3e5111
     /* Remove the stub console added by qemuDomainChrPreInsert */
3e5111
     if (vmdef->nserials == 0 && vmdef->nconsoles == 1 &&
3e5111
         chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL) {
3e5111
-        VIR_FREE(vmdef->consoles[0]);
3e5111
+        virDomainChrDefFree(vmdef->consoles[0]);
3e5111
         VIR_FREE(vmdef->consoles);
3e5111
         vmdef->nconsoles = 0;
3e5111
     }
3e5111
-- 
3e5111
2.13.1
3e5111