render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
404507
From 6e8cb0e122f7c269d1252ed7d55a7c82ae0062eb Mon Sep 17 00:00:00 2001
404507
Message-Id: <6e8cb0e122f7c269d1252ed7d55a7c82ae0062eb@dist-git>
404507
From: Andrea Bolognani <abologna@redhat.com>
404507
Date: Wed, 29 Nov 2017 16:23:03 +0100
404507
Subject: [PATCH] conf: Improve virDomainChrTargetDefFormat()
404507
404507
Make the switch statement type-aware, avoid calling
404507
virDomainChrTargetTypeToString() more than once and check its
404507
return value before using it.
404507
404507
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
404507
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
404507
(cherry picked from commit 46084f2aa1e9188709fcd7abc5c41fe165b2b19b)
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 | 29 ++++++++++++++++++++++-------
404507
 1 file changed, 22 insertions(+), 7 deletions(-)
404507
404507
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
404507
index 346edaa6bd..2489705d6b 100644
404507
--- a/src/conf/domain_conf.c
404507
+++ b/src/conf/domain_conf.c
404507
@@ -23945,7 +23945,7 @@ virDomainChrTargetDefFormat(virBufferPtr buf,
404507
     const char *targetType = virDomainChrTargetTypeToString(def->deviceType,
404507
                                                             def->targetType);
404507
 
404507
-    switch (def->deviceType) {
404507
+    switch ((virDomainChrDeviceType) def->deviceType) {
404507
     case VIR_DOMAIN_CHR_DEVICE_TYPE_CHANNEL: {
404507
         if (!targetType) {
404507
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
404507
@@ -23992,28 +23992,43 @@ virDomainChrTargetDefFormat(virBufferPtr buf,
404507
     }
404507
 
404507
     case VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE:
404507
+        if (!targetType) {
404507
+            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
404507
+                           _("Could not format console target type"));
404507
+            return -1;
404507
+        }
404507
+
404507
         virBufferAsprintf(buf,
404507
                           "<target type='%s' port='%d'/>\n",
404507
-                          virDomainChrTargetTypeToString(def->deviceType,
404507
-                                                         def->targetType),
404507
-                          def->target.port);
404507
+                          targetType, def->target.port);
404507
         break;
404507
 
404507
     case VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL:
404507
+        if (!targetType) {
404507
+            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
404507
+                           _("Could not format serial target type"));
404507
+            return -1;
404507
+        }
404507
+
404507
         if (def->targetType != VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_NONE) {
404507
             virBufferAsprintf(buf,
404507
                               "<target type='%s' port='%d'/>\n",
404507
-                              virDomainChrTargetTypeToString(def->deviceType,
404507
-                                                             def->targetType),
404507
+                              targetType,
404507
                               def->target.port);
404507
             break;
404507
         }
404507
         ATTRIBUTE_FALLTHROUGH;
404507
 
404507
-    default:
404507
+    case VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL:
404507
         virBufferAsprintf(buf, "<target port='%d'/>\n",
404507
                           def->target.port);
404507
         break;
404507
+
404507
+    case VIR_DOMAIN_CHR_DEVICE_TYPE_LAST:
404507
+        virReportError(VIR_ERR_INTERNAL_ERROR,
404507
+                       _("unexpected char device type %d"),
404507
+                       def->deviceType);
404507
+        return -1;
404507
     }
404507
 
404507
     return 0;
404507
-- 
404507
2.15.1
404507