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