c1c534
From 73650fdd9de90d6f5a6f4a3c6c19d60368411b07 Mon Sep 17 00:00:00 2001
c1c534
Message-Id: <73650fdd9de90d6f5a6f4a3c6c19d60368411b07@dist-git>
c1c534
From: Andrea Bolognani <abologna@redhat.com>
c1c534
Date: Wed, 29 Nov 2017 16:23:02 +0100
c1c534
Subject: [PATCH] conf: Check virDomainChrSourceDefFormat() return value
c1c534
c1c534
The function can fail, but none of the caller were accounting
c1c534
for that.
c1c534
c1c534
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
c1c534
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
c1c534
(cherry picked from commit 2cd323e382b4abfffda52fe49d1b50a087716e01)
c1c534
c1c534
https://bugzilla.redhat.com/show_bug.cgi?id=1449265
c1c534
https://bugzilla.redhat.com/show_bug.cgi?id=1511421
c1c534
https://bugzilla.redhat.com/show_bug.cgi?id=1512929
c1c534
https://bugzilla.redhat.com/show_bug.cgi?id=1512934
c1c534
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c1c534
---
c1c534
 src/conf/domain_conf.c | 34 ++++++++++++++++++++++++----------
c1c534
 1 file changed, 24 insertions(+), 10 deletions(-)
c1c534
c1c534
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
c1c534
index cf1bd030a0..346edaa6bd 100644
c1c534
--- a/src/conf/domain_conf.c
c1c534
+++ b/src/conf/domain_conf.c
c1c534
@@ -24045,7 +24045,9 @@ virDomainChrDefFormat(virBufferPtr buf,
c1c534
     if (virDomainChrAttrsDefFormat(buf, def->source, tty_compat) < 0)
c1c534
         return -1;
c1c534
     virBufferAddLit(buf, ">\n");
c1c534
-    virDomainChrSourceDefFormat(buf, def->source, flags);
c1c534
+
c1c534
+    if (virDomainChrSourceDefFormat(buf, def->source, flags) < 0)
c1c534
+        return -1;
c1c534
 
c1c534
     if (virDomainChrTargetDefFormat(buf, def, flags) < 0)
c1c534
         return -1;
c1c534
@@ -24066,13 +24068,14 @@ virDomainSmartcardDefFormat(virBufferPtr buf,
c1c534
     const char *mode = virDomainSmartcardTypeToString(def->type);
c1c534
     virBuffer childBuf = VIR_BUFFER_INITIALIZER;
c1c534
     size_t i;
c1c534
+    int ret = -1;
c1c534
 
c1c534
     virBufferSetChildIndent(&childBuf, buf);
c1c534
 
c1c534
     if (!mode) {
c1c534
         virReportError(VIR_ERR_INTERNAL_ERROR,
c1c534
                        _("unexpected smartcard type %d"), def->type);
c1c534
-        return -1;
c1c534
+        goto cleanup;
c1c534
     }
c1c534
 
c1c534
     switch (def->type) {
c1c534
@@ -24089,23 +24092,25 @@ virDomainSmartcardDefFormat(virBufferPtr buf,
c1c534
         break;
c1c534
 
c1c534
     case VIR_DOMAIN_SMARTCARD_TYPE_PASSTHROUGH:
c1c534
-        virDomainChrSourceDefFormat(&childBuf, def->data.passthru, flags);
c1c534
+        if (virDomainChrSourceDefFormat(&childBuf, def->data.passthru, flags) < 0)
c1c534
+            goto cleanup;
c1c534
         break;
c1c534
 
c1c534
     default:
c1c534
         virReportError(VIR_ERR_INTERNAL_ERROR,
c1c534
                        _("unexpected smartcard type %d"), def->type);
c1c534
-        return -1;
c1c534
+        goto cleanup;
c1c534
     }
c1c534
     virDomainDeviceInfoFormat(&childBuf, &def->info, flags);
c1c534
 
c1c534
     if (virBufferCheckError(&childBuf) < 0)
c1c534
-        return -1;
c1c534
+        goto cleanup;
c1c534
 
c1c534
     virBufferAsprintf(buf, "
c1c534
     if (def->type == VIR_DOMAIN_SMARTCARD_TYPE_PASSTHROUGH &&
c1c534
-        virDomainChrAttrsDefFormat(buf, def->data.passthru, false) < 0)
c1c534
-        return -1;
c1c534
+        virDomainChrAttrsDefFormat(buf, def->data.passthru, false) < 0) {
c1c534
+        goto cleanup;
c1c534
+    }
c1c534
 
c1c534
     if (virBufferUse(&childBuf)) {
c1c534
         virBufferAddLit(buf, ">\n");
c1c534
@@ -24114,7 +24119,12 @@ virDomainSmartcardDefFormat(virBufferPtr buf,
c1c534
     } else {
c1c534
         virBufferAddLit(buf, "/>\n");
c1c534
     }
c1c534
-    return 0;
c1c534
+
c1c534
+    ret = 0;
c1c534
+
c1c534
+ cleanup:
c1c534
+    virBufferFreeAndReset(&childBuf);
c1c534
+    return ret;
c1c534
 }
c1c534
 
c1c534
 static int
c1c534
@@ -24416,7 +24426,8 @@ virDomainRNGDefFormat(virBufferPtr buf,
c1c534
             return -1;
c1c534
         virBufferAddLit(buf, ">\n");
c1c534
         virBufferAdjustIndent(buf, 2);
c1c534
-        virDomainChrSourceDefFormat(buf, def->source.chardev, flags);
c1c534
+        if (virDomainChrSourceDefFormat(buf, def->source.chardev, flags) < 0)
c1c534
+            return -1;
c1c534
         virBufferAdjustIndent(buf, -2);
c1c534
         virBufferAddLit(buf, "</backend>\n");
c1c534
 
c1c534
@@ -25261,7 +25272,10 @@ virDomainRedirdevDefFormat(virBufferPtr buf,
c1c534
         return -1;
c1c534
     virBufferAddLit(buf, ">\n");
c1c534
     virBufferAdjustIndent(buf, 2);
c1c534
-    virDomainChrSourceDefFormat(buf, def->source, flags);
c1c534
+
c1c534
+    if (virDomainChrSourceDefFormat(buf, def->source, flags) < 0)
c1c534
+        return -1;
c1c534
+
c1c534
     virDomainDeviceInfoFormat(buf, &def->info,
c1c534
                               flags | VIR_DOMAIN_DEF_FORMAT_ALLOW_BOOT);
c1c534
     virBufferAdjustIndent(buf, -2);
c1c534
-- 
c1c534
2.15.1
c1c534