render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
e6dfe8
From fd11d55c30553c37d3d71d202348ac22029cba8d Mon Sep 17 00:00:00 2001
e6dfe8
Message-Id: <fd11d55c30553c37d3d71d202348ac22029cba8d@dist-git>
e6dfe8
From: Michal Privoznik <mprivozn@redhat.com>
e6dfe8
Date: Fri, 13 Apr 2018 10:09:29 +0200
e6dfe8
Subject: [PATCH] qemu: Use dynamic buffer for storing PTY aliases
e6dfe8
MIME-Version: 1.0
e6dfe8
Content-Type: text/plain; charset=UTF-8
e6dfe8
Content-Transfer-Encoding: 8bit
e6dfe8
e6dfe8
RHEL-7.6: https://bugzilla.redhat.com/show_bug.cgi?id=1560976
e6dfe8
RHEL-7.5.z: https://bugzilla.redhat.com/show_bug.cgi?id=1566525
e6dfe8
e6dfe8
For historical reasons we've used 32 bytes long static buffer for
e6dfe8
storing PTY aliases. This breaks users scenario where they try to
e6dfe8
start a machine with user alias consisting of "ua-$uuid".
e6dfe8
e6dfe8
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
e6dfe8
(cherry picked from commit c4c32cb300beba41ecbca3ee4884c65630bde861)
e6dfe8
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
e6dfe8
Reviewed-by: Ján Tomko <jtomko@redhat.com>
e6dfe8
Reviewed-by: Erik Skultety <eskultet@redhat.com>
e6dfe8
---
e6dfe8
 src/qemu/qemu_process.c | 39 ++++++++++++++++++++-------------------
e6dfe8
 1 file changed, 20 insertions(+), 19 deletions(-)
e6dfe8
e6dfe8
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
e6dfe8
index c86f7d3c5b..04147f381e 100644
e6dfe8
--- a/src/qemu/qemu_process.c
e6dfe8
+++ b/src/qemu/qemu_process.c
e6dfe8
@@ -1931,21 +1931,18 @@ qemuProcessLookupPTYs(virDomainChrDefPtr *devices,
e6dfe8
                       int count,
e6dfe8
                       virHashTablePtr info)
e6dfe8
 {
e6dfe8
+    char *id = NULL;
e6dfe8
     size_t i;
e6dfe8
+    int ret = -1;
e6dfe8
 
e6dfe8
     for (i = 0; i < count; i++) {
e6dfe8
         virDomainChrDefPtr chr = devices[i];
e6dfe8
         if (chr->source->type == VIR_DOMAIN_CHR_TYPE_PTY) {
e6dfe8
-            char id[32];
e6dfe8
             qemuMonitorChardevInfoPtr entry;
e6dfe8
 
e6dfe8
-            if (snprintf(id, sizeof(id), "char%s",
e6dfe8
-                         chr->info.alias) >= sizeof(id)) {
e6dfe8
-                virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
e6dfe8
-                               _("failed to format device alias "
e6dfe8
-                                 "for PTY retrieval"));
e6dfe8
+            VIR_FREE(id);
e6dfe8
+            if (virAsprintf(&id, "char%s", chr->info.alias) < 0)
e6dfe8
                 return -1;
e6dfe8
-            }
e6dfe8
 
e6dfe8
             entry = virHashLookup(info, id);
e6dfe8
             if (!entry || !entry->ptyPath) {
e6dfe8
@@ -1955,7 +1952,7 @@ qemuProcessLookupPTYs(virDomainChrDefPtr *devices,
e6dfe8
                      */
e6dfe8
                     virReportError(VIR_ERR_INTERNAL_ERROR,
e6dfe8
                                    _("no assigned pty for device %s"), id);
e6dfe8
-                    return -1;
e6dfe8
+                    goto cleanup;
e6dfe8
                 } else {
e6dfe8
                     /* 'info chardev' had no pty path for this chardev,
e6dfe8
                      * but the log output had, so we're fine
e6dfe8
@@ -1966,11 +1963,14 @@ qemuProcessLookupPTYs(virDomainChrDefPtr *devices,
e6dfe8
 
e6dfe8
             VIR_FREE(chr->source->data.file.path);
e6dfe8
             if (VIR_STRDUP(chr->source->data.file.path, entry->ptyPath) < 0)
e6dfe8
-                return -1;
e6dfe8
+                goto cleanup;
e6dfe8
         }
e6dfe8
     }
e6dfe8
 
e6dfe8
-    return 0;
e6dfe8
+    ret = 0;
e6dfe8
+ cleanup:
e6dfe8
+    VIR_FREE(id);
e6dfe8
+    return ret;
e6dfe8
 }
e6dfe8
 
e6dfe8
 static int
e6dfe8
@@ -2022,7 +2022,8 @@ qemuProcessRefreshChannelVirtioState(virQEMUDriverPtr driver,
e6dfe8
     int agentReason = VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_REASON_CHANNEL;
e6dfe8
     qemuMonitorChardevInfoPtr entry;
e6dfe8
     virObjectEventPtr event = NULL;
e6dfe8
-    char id[32];
e6dfe8
+    char *id = NULL;
e6dfe8
+    int ret = -1;
e6dfe8
 
e6dfe8
     if (booted)
e6dfe8
         agentReason = VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_REASON_DOMAIN_STARTED;
e6dfe8
@@ -2030,13 +2031,10 @@ qemuProcessRefreshChannelVirtioState(virQEMUDriverPtr driver,
e6dfe8
     for (i = 0; i < vm->def->nchannels; i++) {
e6dfe8
         virDomainChrDefPtr chr = vm->def->channels[i];
e6dfe8
         if (chr->targetType == VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO) {
e6dfe8
-            if (snprintf(id, sizeof(id), "char%s",
e6dfe8
-                         chr->info.alias) >= sizeof(id)) {
e6dfe8
-                virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
e6dfe8
-                               _("failed to format device alias "
e6dfe8
-                                 "for PTY retrieval"));
e6dfe8
-                return -1;
e6dfe8
-            }
e6dfe8
+
e6dfe8
+            VIR_FREE(id);
e6dfe8
+            if (virAsprintf(&id, "char%s", chr->info.alias) < 0)
e6dfe8
+                goto cleanup;
e6dfe8
 
e6dfe8
             /* port state not reported */
e6dfe8
             if (!(entry = virHashLookup(info, id)) ||
e6dfe8
@@ -2053,7 +2051,10 @@ qemuProcessRefreshChannelVirtioState(virQEMUDriverPtr driver,
e6dfe8
         }
e6dfe8
     }
e6dfe8
 
e6dfe8
-    return 0;
e6dfe8
+    ret = 0;
e6dfe8
+ cleanup:
e6dfe8
+    VIR_FREE(id);
e6dfe8
+    return ret;
e6dfe8
 }
e6dfe8
 
e6dfe8
 
e6dfe8
-- 
e6dfe8
2.17.0
e6dfe8