[libvirt] [PATCH] qemu: Use dynamic buffer for storing PTY aliases

Michal Privoznik posted 1 patch 6 years ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/03f8bdf8816cb3ebbbf9c3fc41e9bb29573507dd.1522306336.git.mprivozn@redhat.com
Test syntax-check passed
src/qemu/qemu_process.c | 39 ++++++++++++++++++++-------------------
1 file changed, 20 insertions(+), 19 deletions(-)
[libvirt] [PATCH] qemu: Use dynamic buffer for storing PTY aliases
Posted by Michal Privoznik 6 years ago
https://bugzilla.redhat.com/show_bug.cgi?id=1560976

For historical reasons we've used 32 bytes long static buffer for
storing PTY aliases. This breaks users scenario where they try to
start a machine with user alias consisting of "ua-$uuid".

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/qemu/qemu_process.c | 39 ++++++++++++++++++++-------------------
 1 file changed, 20 insertions(+), 19 deletions(-)

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 1afb71f113..c0105c8b84 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -1949,21 +1949,18 @@ qemuProcessLookupPTYs(virDomainChrDefPtr *devices,
                       int count,
                       virHashTablePtr info)
 {
+    char *id = NULL;
     size_t i;
+    int ret = -1;
 
     for (i = 0; i < count; i++) {
         virDomainChrDefPtr chr = devices[i];
         if (chr->source->type == VIR_DOMAIN_CHR_TYPE_PTY) {
-            char id[32];
             qemuMonitorChardevInfoPtr entry;
 
-            if (snprintf(id, sizeof(id), "char%s",
-                         chr->info.alias) >= sizeof(id)) {
-                virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                               _("failed to format device alias "
-                                 "for PTY retrieval"));
+            VIR_FREE(id);
+            if (virAsprintf(&id, "char%s", chr->info.alias) < 0)
                 return -1;
-            }
 
             entry = virHashLookup(info, id);
             if (!entry || !entry->ptyPath) {
@@ -1973,7 +1970,7 @@ qemuProcessLookupPTYs(virDomainChrDefPtr *devices,
                      */
                     virReportError(VIR_ERR_INTERNAL_ERROR,
                                    _("no assigned pty for device %s"), id);
-                    return -1;
+                    goto cleanup;
                 } else {
                     /* 'info chardev' had no pty path for this chardev,
                      * but the log output had, so we're fine
@@ -1984,11 +1981,14 @@ qemuProcessLookupPTYs(virDomainChrDefPtr *devices,
 
             VIR_FREE(chr->source->data.file.path);
             if (VIR_STRDUP(chr->source->data.file.path, entry->ptyPath) < 0)
-                return -1;
+                goto cleanup;
         }
     }
 
-    return 0;
+    ret = 0;
+ cleanup:
+    VIR_FREE(id);
+    return ret;
 }
 
 static int
@@ -2040,7 +2040,8 @@ qemuProcessRefreshChannelVirtioState(virQEMUDriverPtr driver,
     int agentReason = VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_REASON_CHANNEL;
     qemuMonitorChardevInfoPtr entry;
     virObjectEventPtr event = NULL;
-    char id[32];
+    char *id = NULL;
+    int ret = -1;
 
     if (booted)
         agentReason = VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_REASON_DOMAIN_STARTED;
@@ -2048,13 +2049,10 @@ qemuProcessRefreshChannelVirtioState(virQEMUDriverPtr driver,
     for (i = 0; i < vm->def->nchannels; i++) {
         virDomainChrDefPtr chr = vm->def->channels[i];
         if (chr->targetType == VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO) {
-            if (snprintf(id, sizeof(id), "char%s",
-                         chr->info.alias) >= sizeof(id)) {
-                virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                               _("failed to format device alias "
-                                 "for PTY retrieval"));
-                return -1;
-            }
+
+            VIR_FREE(id);
+            if (virAsprintf(&id, "char%s", chr->info.alias) < 0)
+                goto cleanup;
 
             /* port state not reported */
             if (!(entry = virHashLookup(info, id)) ||
@@ -2071,7 +2069,10 @@ qemuProcessRefreshChannelVirtioState(virQEMUDriverPtr driver,
         }
     }
 
-    return 0;
+    ret = 0;
+ cleanup:
+    VIR_FREE(id);
+    return ret;
 }
 
 
-- 
2.16.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] qemu: Use dynamic buffer for storing PTY aliases
Posted by Peter Krempa 6 years ago
On Thu, Mar 29, 2018 at 08:52:16 +0200, Michal Privoznik wrote:
> https://bugzilla.redhat.com/show_bug.cgi?id=1560976
> 
> For historical reasons we've used 32 bytes long static buffer for
> storing PTY aliases. This breaks users scenario where they try to
> start a machine with user alias consisting of "ua-$uuid".
> 
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
>  src/qemu/qemu_process.c | 39 ++++++++++++++++++++-------------------
>  1 file changed, 20 insertions(+), 19 deletions(-)

ACK
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] qemu: Use dynamic buffer for storing PTY aliases
Posted by Michal Privoznik 6 years ago
On 03/29/2018 09:18 AM, Peter Krempa wrote:
> On Thu, Mar 29, 2018 at 08:52:16 +0200, Michal Privoznik wrote:
>> https://bugzilla.redhat.com/show_bug.cgi?id=1560976
>>
>> For historical reasons we've used 32 bytes long static buffer for
>> storing PTY aliases. This breaks users scenario where they try to
>> start a machine with user alias consisting of "ua-$uuid".
>>
>> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
>> ---
>>  src/qemu/qemu_process.c | 39 ++++++++++++++++++++-------------------
>>  1 file changed, 20 insertions(+), 19 deletions(-)
> 
> ACK
> 

and safe for freeze? ;-)

Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] qemu: Use dynamic buffer for storing PTY aliases
Posted by Peter Krempa 6 years ago
On Thu, Mar 29, 2018 at 10:13:43 +0200, Michal Privoznik wrote:
> On 03/29/2018 09:18 AM, Peter Krempa wrote:
> > On Thu, Mar 29, 2018 at 08:52:16 +0200, Michal Privoznik wrote:
> >> https://bugzilla.redhat.com/show_bug.cgi?id=1560976
> >>
> >> For historical reasons we've used 32 bytes long static buffer for
> >> storing PTY aliases. This breaks users scenario where they try to
> >> start a machine with user alias consisting of "ua-$uuid".
> >>
> >> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> >> ---
> >>  src/qemu/qemu_process.c | 39 ++++++++++++++++++++-------------------
> >>  1 file changed, 20 insertions(+), 19 deletions(-)
> > 
> > ACK
> > 
> 
> and safe for freeze? ;-)

Not any more since rc2 was tagged an hour ago.
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] qemu: Use dynamic buffer for storing PTY aliases
Posted by Michal Privoznik 6 years ago
On 03/29/2018 10:22 AM, Peter Krempa wrote:
> On Thu, Mar 29, 2018 at 10:13:43 +0200, Michal Privoznik wrote:
>> On 03/29/2018 09:18 AM, Peter Krempa wrote:
>>> On Thu, Mar 29, 2018 at 08:52:16 +0200, Michal Privoznik wrote:
>>>> https://bugzilla.redhat.com/show_bug.cgi?id=1560976
>>>>
>>>> For historical reasons we've used 32 bytes long static buffer for
>>>> storing PTY aliases. This breaks users scenario where they try to
>>>> start a machine with user alias consisting of "ua-$uuid".
>>>>
>>>> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
>>>> ---
>>>>  src/qemu/qemu_process.c | 39 ++++++++++++++++++++-------------------
>>>>  1 file changed, 20 insertions(+), 19 deletions(-)
>>>
>>> ACK
>>>
>>
>> and safe for freeze? ;-)
> 
> Not any more since rc2 was tagged an hour ago.
> 

Oh, okay. I'll wait for the release then.

Thanks,
Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list