From nobody Tue Apr 30 09:04:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1522306349247124.05567921745057; Wed, 28 Mar 2018 23:52:29 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 36F61C065105; Thu, 29 Mar 2018 06:52:27 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 990F860F8C; Thu, 29 Mar 2018 06:52:25 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 35DC14CA99; Thu, 29 Mar 2018 06:52:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w2T6qLs8018808 for ; Thu, 29 Mar 2018 02:52:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id 923E8D7DF2; Thu, 29 Mar 2018 06:52:21 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 38C111C717 for ; Thu, 29 Mar 2018 06:52:18 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 29 Mar 2018 08:52:16 +0200 Message-Id: <03f8bdf8816cb3ebbbf9c3fc41e9bb29573507dd.1522306336.git.mprivozn@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] qemu: Use dynamic buffer for storing PTY aliases X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 29 Mar 2018 06:52:28 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" https://bugzilla.redhat.com/show_bug.cgi?id=3D1560976 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 --- 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 =3D NULL; size_t i; + int ret =3D -1; =20 for (i =3D 0; i < count; i++) { virDomainChrDefPtr chr =3D devices[i]; if (chr->source->type =3D=3D VIR_DOMAIN_CHR_TYPE_PTY) { - char id[32]; qemuMonitorChardevInfoPtr entry; =20 - if (snprintf(id, sizeof(id), "char%s", - chr->info.alias) >=3D 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; - } =20 entry =3D 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, =20 VIR_FREE(chr->source->data.file.path); if (VIR_STRDUP(chr->source->data.file.path, entry->ptyPath) < = 0) - return -1; + goto cleanup; } } =20 - return 0; + ret =3D 0; + cleanup: + VIR_FREE(id); + return ret; } =20 static int @@ -2040,7 +2040,8 @@ qemuProcessRefreshChannelVirtioState(virQEMUDriverPtr= driver, int agentReason =3D VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_REASON_CH= ANNEL; qemuMonitorChardevInfoPtr entry; virObjectEventPtr event =3D NULL; - char id[32]; + char *id =3D NULL; + int ret =3D -1; =20 if (booted) agentReason =3D VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_REASON_DO= MAIN_STARTED; @@ -2048,13 +2049,10 @@ qemuProcessRefreshChannelVirtioState(virQEMUDriverP= tr driver, for (i =3D 0; i < vm->def->nchannels; i++) { virDomainChrDefPtr chr =3D vm->def->channels[i]; if (chr->targetType =3D=3D VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRT= IO) { - if (snprintf(id, sizeof(id), "char%s", - chr->info.alias) >=3D 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; =20 /* port state not reported */ if (!(entry =3D virHashLookup(info, id)) || @@ -2071,7 +2069,10 @@ qemuProcessRefreshChannelVirtioState(virQEMUDriverPt= r driver, } } =20 - return 0; + ret =3D 0; + cleanup: + VIR_FREE(id); + return ret; } =20 =20 --=20 2.16.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list