render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
c401cc
From 31d35776ac5aa93f97d1f3516630137664f48881 Mon Sep 17 00:00:00 2001
c401cc
Message-Id: <31d35776ac5aa93f97d1f3516630137664f48881@dist-git>
c401cc
From: Peter Krempa <pkrempa@redhat.com>
c401cc
Date: Wed, 26 Feb 2014 14:54:48 +0100
c401cc
Subject: [PATCH] snapshot: conf: Fix NULL dereference when <driver> element is
c401cc
 empty
c401cc
c401cc
https://bugzilla.redhat.com/show_bug.cgi?id=1032370
c401cc
c401cc
Consider the following valid snapshot XML as the <driver> element is
c401cc
allowed to be empty in the domainsnapshot.rng schema:
c401cc
c401cc
$ cat snap.xml
c401cc
<domainsnapshot>
c401cc
  <disks>
c401cc
    <disk name='vda' snapshot='external'>
c401cc
      <source file='/tmp/foo'/>
c401cc
      <driver/>
c401cc
    </disk>
c401cc
  </disks>
c401cc
</domainsnapshot>
c401cc
c401cc
produces the following error:
c401cc
c401cc
$ virsh snapshot-create domain snap.xml
c401cc
error: internal error: unknown disk snapshot driver '(null)'
c401cc
c401cc
The driver type is parsed as NULL from the XML as the attribute is not
c401cc
present and then directly used to produce the error message.
c401cc
c401cc
With this patch the attempt to parse the driver type is skipped if not
c401cc
present to avoid changing the schema to forbid the empty driver element.
c401cc
c401cc
(cherry picked from commit 5a66c667ff5cae61c2ad2e646c8eb3eedc67f925)
c401cc
c401cc
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c401cc
---
c401cc
 src/conf/snapshot_conf.c | 16 +++++++++-------
c401cc
 1 file changed, 9 insertions(+), 7 deletions(-)
c401cc
c401cc
diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c
c401cc
index 29e12b7..a1fd723 100644
c401cc
--- a/src/conf/snapshot_conf.c
c401cc
+++ b/src/conf/snapshot_conf.c
c401cc
@@ -154,15 +154,17 @@ virDomainSnapshotDiskDefParseXML(xmlNodePtr node,
c401cc
         } else if (!def->format &&
c401cc
                    xmlStrEqual(cur->name, BAD_CAST "driver")) {
c401cc
             char *driver = virXMLPropString(cur, "type");
c401cc
-            def->format = virStorageFileFormatTypeFromString(driver);
c401cc
-            if (def->format <= 0) {
c401cc
-                virReportError(VIR_ERR_INTERNAL_ERROR,
c401cc
-                               _("unknown disk snapshot driver '%s'"),
c401cc
-                               driver);
c401cc
+            if (driver) {
c401cc
+                def->format = virStorageFileFormatTypeFromString(driver);
c401cc
+                if (def->format <= 0) {
c401cc
+                    virReportError(VIR_ERR_INTERNAL_ERROR,
c401cc
+                                   _("unknown disk snapshot driver '%s'"),
c401cc
+                                   driver);
c401cc
+                    VIR_FREE(driver);
c401cc
+                    goto cleanup;
c401cc
+                }
c401cc
                 VIR_FREE(driver);
c401cc
-                goto cleanup;
c401cc
             }
c401cc
-            VIR_FREE(driver);
c401cc
         }
c401cc
     }
c401cc
 
c401cc
-- 
c401cc
1.9.0
c401cc