render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
Blob Blame History Raw
From 550637214e4df0cd44d64e83a0e57fc37f470bdb Mon Sep 17 00:00:00 2001
Message-Id: <550637214e4df0cd44d64e83a0e57fc37f470bdb@dist-git>
From: Peter Krempa <pkrempa@redhat.com>
Date: Thu, 22 Jan 2015 15:53:51 +0100
Subject: [PATCH] conf: Don't corrupt metadata on OOM

https://bugzilla.redhat.com/show_bug.cgi?id=1184929

Eric Blake suggested that we could do a little better in case copying of
the metadata to be set fails. With this patch, the old metadata is
discarded after the new string is copied successfuly.

(cherry picked from commit 7655ed0802eecc3d8486a0360d2326ecd052e477)

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/conf/domain_conf.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 4dbe3fc..c4829ff 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -19044,19 +19044,24 @@ virDomainDefSetMetadata(virDomainDefPtr def,
     xmlDocPtr doc = NULL;
     xmlNodePtr old;
     xmlNodePtr new;
+    char *tmp;
     int ret = -1;
 
     switch ((virDomainMetadataType) type) {
     case VIR_DOMAIN_METADATA_DESCRIPTION:
+        if (VIR_STRDUP(tmp, metadata) < 0)
+            goto cleanup;
+
         VIR_FREE(def->description);
-        if (VIR_STRDUP(def->description, metadata) < 0)
-            goto cleanup;
+        def->description = tmp;
         break;
 
     case VIR_DOMAIN_METADATA_TITLE:
+        if (VIR_STRDUP(tmp, metadata) < 0)
+            goto cleanup;
+
         VIR_FREE(def->title);
-        if (VIR_STRDUP(def->title, metadata) < 0)
-            goto cleanup;
+        def->title = tmp;
         break;
 
     case VIR_DOMAIN_METADATA_ELEMENT:
-- 
2.2.1