From nobody Mon Apr 29 15:58:11 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 1516991371673219.30831337923394; Fri, 26 Jan 2018 10:29:31 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E10A61752A3; Fri, 26 Jan 2018 18:29:29 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DF1BE5EE1B; Fri, 26 Jan 2018 18:29:27 +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 4EDEA18033DB; Fri, 26 Jan 2018 18:29:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w0QIQoJa016255 for ; Fri, 26 Jan 2018 13:26:50 -0500 Received: by smtp.corp.redhat.com (Postfix) id 252956018E; Fri, 26 Jan 2018 18:26:50 +0000 (UTC) Received: from vhost2.laine.org (ovpn-116-52.phx2.redhat.com [10.3.116.52]) by smtp.corp.redhat.com (Postfix) with ESMTP id 55DE360176; Fri, 26 Jan 2018 18:26:45 +0000 (UTC) From: Laine Stump To: libvir-list@redhat.com Date: Fri, 26 Jan 2018 13:26:41 -0500 Message-Id: <20180126182641.23835-1-laine@laine.org> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Jan Tomko Subject: [libvirt] [PATCH v2] vbox: fix SEGV during dumpxml of a serial port 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 26 Jan 2018 18:29:30 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" commit 77a12987a48 changed the "virDomainChrSourceDef source" inside virDomainChrDef to "virDomainChrSourceDefPtr source", and started allocating source inside virDomainChrDefNew(), but vboxDumpSerial() was allocating a virDomainChrDef with a simple VIR_ALLOC() (i.e. never calling virDomainChrDefNew()), so source was never initialized, leading to a SEGV any time a serial port was present. The same problem was created in vboxDumpParallel(). This patch changes vboxDumpSerial() and vboxDumpParallel() to use virDomainChrDefNew() instead of VIR_ALLOC(), and changes both of those functions to return an error if virDomainChrDef() (or any other allocation) fails. This resolves: https://bugzilla.redhat.com/1536649 --- Change from V1: Due to reviews of V1 whining about the patch calling out the lack of returning failure on OOM in a comment rather than fixing it, V2 changes both functions to return 0/-1, and their caller to abort the dumpxml if they return -1. (If I'd taken the extra 30 seconds to look one level up the call chain before posting V1, I would have done that to begin with - there's really nothing complicated about the change, so I'm just as comfortable posting this V2 patch without being able to test as I was with V1). src/vbox/vbox_common.c | 43 +++++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index 33aefabe5..e8381ac95 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -3862,7 +3862,7 @@ vboxDumpAudio(virDomainDefPtr def, vboxDriverPtr data= ATTRIBUTE_UNUSED, } } =20 -static void +static int vboxDumpSerial(virDomainDefPtr def, vboxDriverPtr data, IMachine *machine,= PRUint32 serialPortCount) { PRUint32 serialPortIncCount =3D 0; @@ -3886,9 +3886,15 @@ vboxDumpSerial(virDomainDefPtr def, vboxDriverPtr da= ta, IMachine *machine, PRUin } =20 /* Allocate memory for the serial ports which are enabled */ - if ((def->nserials > 0) && (VIR_ALLOC_N(def->serials, def->nserials) >= =3D 0)) { - for (i =3D 0; i < def->nserials; i++) - ignore_value(VIR_ALLOC(def->serials[i])); + if (def->nserials > 0) { + if (VIR_ALLOC_N(def->serials, def->nserials) < 0) + return -1; + + for (i =3D 0; i < def->nserials; i++) { + def->serials[i] =3D virDomainChrDefNew(NULL); + if (!def->serials[i]) + return -1; + } } =20 /* Now get the details about the serial ports here */ @@ -3936,7 +3942,8 @@ vboxDumpSerial(virDomainDefPtr def, vboxDriverPtr dat= a, IMachine *machine, PRUin =20 if (pathUtf16) { VBOX_UTF16_TO_UTF8(pathUtf16, &path); - ignore_value(VIR_STRDUP(def->serials[serialPortIncCoun= t]->source->data.file.path, path)); + if (VIR_STRDUP(def->serials[serialPortIncCount]->sourc= e->data.file.path, path) < 0) + return -1; } =20 serialPortIncCount++; @@ -3948,9 +3955,10 @@ vboxDumpSerial(virDomainDefPtr def, vboxDriverPtr da= ta, IMachine *machine, PRUin VBOX_RELEASE(serialPort); } } + return 0; } =20 -static void +static int vboxDumpParallel(virDomainDefPtr def, vboxDriverPtr data, IMachine *machin= e, PRUint32 parallelPortCount) { PRUint32 parallelPortIncCount =3D 0; @@ -3974,9 +3982,15 @@ vboxDumpParallel(virDomainDefPtr def, vboxDriverPtr = data, IMachine *machine, PRU } =20 /* Allocate memory for the parallel ports which are enabled */ - if ((def->nparallels > 0) && (VIR_ALLOC_N(def->parallels, def->nparall= els) >=3D 0)) { - for (i =3D 0; i < def->nparallels; i++) - ignore_value(VIR_ALLOC(def->parallels[i])); + if (def->nparallels > 0) { + if (VIR_ALLOC_N(def->parallels, def->nparallels) < 0) + return -1; + + for (i =3D 0; i < def->nparallels; i++) { + def->parallels[i] =3D virDomainChrDefNew(NULL); + if (!def->parallels[i]) + return -1; + } } =20 /* Now get the details about the parallel ports here */ @@ -4011,7 +4025,8 @@ vboxDumpParallel(virDomainDefPtr def, vboxDriverPtr d= ata, IMachine *machine, PRU gVBoxAPI.UIParallelPort.GetPath(parallelPort, &pathUtf16); =20 VBOX_UTF16_TO_UTF8(pathUtf16, &path); - ignore_value(VIR_STRDUP(def->parallels[parallelPortIncCoun= t]->source->data.file.path, path)); + if (VIR_STRDUP(def->parallels[parallelPortIncCount]->sourc= e->data.file.path, path) < 0) + return -1; =20 parallelPortIncCount++; =20 @@ -4022,6 +4037,7 @@ vboxDumpParallel(virDomainDefPtr def, vboxDriverPtr d= ata, IMachine *machine, PRU VBOX_RELEASE(parallelPort); } } + return 0; } =20 static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) @@ -4162,8 +4178,11 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, = unsigned int flags) vboxDumpSharedFolders(def, data, machine); vboxDumpNetwork(def, data, machine, networkAdapterCount); vboxDumpAudio(def, data, machine); - vboxDumpSerial(def, data, machine, serialPortCount); - vboxDumpParallel(def, data, machine, parallelPortCount); + + if (vboxDumpSerial(def, data, machine, serialPortCount) < 0) + goto cleanup; + if (vboxDumpParallel(def, data, machine, parallelPortCount) < 0) + goto cleanup; =20 /* dump USB devices/filters if active */ vboxHostDeviceGetXMLDesc(data, def, machine); --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list