From nobody Mon Feb 9 04:59:52 2026 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 1501076024172290.34413495246656; Wed, 26 Jul 2017 06:33:44 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3FAFAD69CA; Wed, 26 Jul 2017 13:33:40 +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 A2E198FBE8; Wed, 26 Jul 2017 13:33:39 +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 71FC14BB79; Wed, 26 Jul 2017 13:33:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v6QDUF3e012106 for ; Wed, 26 Jul 2017 09:30:15 -0400 Received: by smtp.corp.redhat.com (Postfix) id B76BF78121; Wed, 26 Jul 2017 13:30:15 +0000 (UTC) Received: from dnr.brq.redhat.com (unknown [10.43.2.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3EDFE7ADB5 for ; Wed, 26 Jul 2017 13:30:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3FAFAD69CA Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Wed, 26 Jul 2017 15:29:35 +0200 Message-Id: <92409353e297a7199b4683a4b672d1d1400de829.1501075760.git.jtomko@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 7/8] conf: check for buffer errors before virBufferUse 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 26 Jul 2017 13:33:41 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" After an OOM error, virBuffer* APIs set buf->use to zero. Adding a buffer to the parent buffer only if use is non-zero would quitely drop data on error. Check the error beforehand to make sure buf->use is zero because we have not attempted to add anything to it. Reviewed-by: John Ferlan --- src/conf/capabilities.c | 5 +++++ src/conf/cpu_conf.c | 4 ++++ src/conf/domain_conf.c | 31 +++++++++++++++++++++++++++++-- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 0f99f3096..db7efffdf 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -930,6 +930,11 @@ virCapabilitiesFormatCaches(virBufferPtr buf, bank->controls[j]->max_allocation); } =20 + if (virBufferCheckError(&controlBuf) < 0) { + VIR_FREE(cpus_str); + return -1; + } + if (virBufferUse(&controlBuf)) { virBufferAddLit(buf, ">\n"); virBufferAddBuffer(buf, &controlBuf); diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c index da40e9ba9..065b4df99 100644 --- a/src/conf/cpu_conf.c +++ b/src/conf/cpu_conf.c @@ -646,6 +646,10 @@ virCPUDefFormatBufFull(virBufferPtr buf, if (virDomainNumaDefCPUFormat(&childrenBuf, numa) < 0) goto cleanup; =20 + if (virBufferCheckError(&attributeBuf) < 0 || + virBufferCheckError(&childrenBuf) < 0) + goto cleanup; + /* Put it all together */ if (virBufferUse(&attributeBuf) || virBufferUse(&childrenBuf)) { virBufferAddLit(buf, "virtio); =20 + if (virBufferCheckError(&driverBuf) < 0) + return -1; + if (virBufferUse(&driverBuf)) { virBufferAddLit(buf, "virtio); =20 - if (virBufferUse(&driverBuf)) { + if (virBufferError(&driverBuf) !=3D 0 || virBufferUse(&driverBuf)) { virBufferAddLit(buf, "\n"); @@ -21891,6 +21894,9 @@ virDomainControllerDefFormat(virBufferPtr buf, "pcihole64>\n", def->opts.pciopts.pcihole64size); } =20 + if (virBufferCheckError(&childBuf) < 0) + return -1; + if (virBufferUse(&childBuf)) { virBufferAddLit(buf, ">\n"); virBufferAddBuffer(buf, &childBuf); @@ -21962,6 +21968,9 @@ virDomainFSDefFormat(virBufferPtr buf, =20 virDomainVirtioOptionsFormat(&driverBuf, def->virtio); =20 + if (virBufferCheckError(&driverBuf) < 0) + return -1; + if (virBufferUse(&driverBuf)) { virBufferAddLit(buf, "\n"); } else { @@ -23309,6 +23321,10 @@ static int virDomainPanicDefFormat(virBufferPtr bu= f, virBufferAdjustIndent(&childrenBuf, indent + 2); if (virDomainDeviceInfoFormat(&childrenBuf, &def->info, 0) < 0) return -1; + + if (virBufferCheckError(&childrenBuf) < 0) + return -1; + if (virBufferUse(&childrenBuf)) { virBufferAddLit(buf, ">\n"); virBufferAddBuffer(buf, &childrenBuf); @@ -23655,6 +23671,9 @@ virDomainInputDefFormat(virBufferPtr buf, if (virDomainDeviceInfoFormat(&childbuf, &def->info, flags) < 0) return -1; =20 + if (virBufferCheckError(&childbuf) < 0) + return -1; + if (!virBufferUse(&childbuf)) { virBufferAddLit(buf, "/>\n"); } else { @@ -24596,6 +24615,9 @@ virDomainCputuneDefFormat(virBufferPtr buf, def->iothreadids[i]->iothread_id); } =20 + if (virBufferCheckError(&childrenBuf) < 0) + return -1; + if (virBufferUse(&childrenBuf)) { virBufferAddLit(buf, "\n"); virBufferAddBuffer(buf, &childrenBuf); @@ -24709,7 +24731,8 @@ virDomainIOMMUDefFormat(virBufferPtr buf, =20 virBufferAsprintf(buf, "model)); - if (virBufferUse(&childBuf)) { + + if (virBufferError(&childBuf) !=3D 0 || virBufferUse(&childBuf)) { virBufferAddLit(buf, ">\n"); virBufferAddBuffer(buf, &childBuf); virBufferAddLit(buf, "\n"); @@ -24847,6 +24870,10 @@ virDomainDefFormatInternal(virDomainDefPtr def, virBufferAdjustIndent(&childrenBuf, -2); virBufferAddLit(&childrenBuf, "\n"); } + + if (virBufferCheckError(&childrenBuf) < 0) + goto error; + if (virBufferUse(&childrenBuf)) { virBufferAddLit(buf, "\n"); virBufferAddBuffer(buf, &childrenBuf); --=20 2.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list