From nobody Tue Feb 10 00:57:44 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1593056083; cv=none; d=zohomail.com; s=zohoarc; b=AL1CP+vLKrN5f4nEV1ySwwYIWy3mHTJ+nJzq9cq7hYhHnupamvaryT+5auIjlyUStAB166o6w/K6NEamkT5gw0JJMMmGcHtUn/Yxkvb2Xncj0MaNCf01QHeYxIo1iMtasBHHDclvC61ikK5ASZhaAEXNXgxbQfTsiEMVyoM5Mqk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593056083; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=h4IRb5SmpbBHKxMU6uWwZIoUSFCYG/vVv/bPkELFlXc=; b=M66B6kBOiySXSmo8TPNjYQdsOmdqbq8cGiZ3PohgH0C/3nQMNwK4yGGofqyVPwThsMWsz+djF49h8yVOzpmwIInHPld5HZUDohdjSHSd5GJX2iAC3Mn3jonAGeRKFGH1gALlcvkgYyRoHNxZWuSZ4hiFN+x66BM897RlUKgx9uY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 159305608332363.6046538973759; Wed, 24 Jun 2020 20:34:43 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-405-LIN_ACATOJC8_VbER4k6Vg-1; Wed, 24 Jun 2020 23:34:40 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4630DEC1AC; Thu, 25 Jun 2020 03:34:32 +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 F26335BAC6; Thu, 25 Jun 2020 03:34:29 +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 C7D40833D3; Thu, 25 Jun 2020 03:34:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 05P3YN3I007781 for ; Wed, 24 Jun 2020 23:34:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id 26C285BAC6; Thu, 25 Jun 2020 03:34:23 +0000 (UTC) Received: from vhost2.laine.org (ovpn-114-28.phx2.redhat.com [10.3.114.28]) by smtp.corp.redhat.com (Postfix) with ESMTP id BE6605BAC0 for ; Thu, 25 Jun 2020 03:34:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593056082; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=h4IRb5SmpbBHKxMU6uWwZIoUSFCYG/vVv/bPkELFlXc=; b=WoAisFU/PJDxjX9YwAaVY5ZGNrYnVZeL20NVj2qJvDOKn/jS3m5i7YKBZWcesm76Vmbex/ kQScLWn3ZUPOz4uhxQ8Uz8hpKdxvvuRVP31ou09IW1S5CGDPEk2sXvz48JnQ1UAjYqq8Sv 34vOw8g4I6JUdKWqQYy1l2807wIrLpY= X-MC-Unique: LIN_ACATOJC8_VbER4k6Vg-1 From: Laine Stump To: libvir-list@redhat.com Subject: [PATCH 03/25] conf: refactor virDomainBlkioDeviceParseXML to remove possible NULL dereference Date: Wed, 24 Jun 2020 23:33:52 -0400 Message-Id: <20200625033414.1819594-4-laine@redhat.com> In-Reply-To: <20200625033414.1819594-1-laine@redhat.com> References: <20200625033414.1819594-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com 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: , 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-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" virDomainBlkioDeviceParseXML() has multiple cases of sending the return from xmlNodeGetContent() directly to virStrToLong_xx() without checking for NULL. Although it is *very* rare for xmlNodeGetContent() to return NULL (possibly it only happens in an OOM condition? The documentation is unclear), it could happen, and the refactor in this patch manages to eliminate several lines of repeated code while adding in a (single) check for NULL. Signed-off-by: Laine Stump --- src/conf/domain_conf.c | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 1916b51d38..8cde1cd0e8 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1628,73 +1628,64 @@ virDomainBlkioDeviceParseXML(xmlNodePtr root, virBlkioDevicePtr dev) { xmlNodePtr node; - g_autofree char *c =3D NULL; + g_autofree char *path =3D NULL; =20 node =3D root->children; while (node) { - if (node->type =3D=3D XML_ELEMENT_NODE) { - if (virXMLNodeNameEqual(node, "path") && !dev->path) { - dev->path =3D (char *)xmlNodeGetContent(node); + g_autofree char *c =3D NULL; + + if (node->type =3D=3D XML_ELEMENT_NODE && + (c =3D (char *)xmlNodeGetContent(node))) { + if (virXMLNodeNameEqual(node, "path") && !path) { + path =3D g_steal_pointer(&c); } else if (virXMLNodeNameEqual(node, "weight")) { - c =3D (char *)xmlNodeGetContent(node); if (virStrToLong_ui(c, NULL, 10, &dev->weight) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("could not parse weight %s"), c); - goto error; + return -1; } - VIR_FREE(c); } else if (virXMLNodeNameEqual(node, "read_bytes_sec")) { - c =3D (char *)xmlNodeGetContent(node); if (virStrToLong_ull(c, NULL, 10, &dev->rbps) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("could not parse read bytes sec %s"), c); - goto error; + return -1; } - VIR_FREE(c); } else if (virXMLNodeNameEqual(node, "write_bytes_sec")) { - c =3D (char *)xmlNodeGetContent(node); if (virStrToLong_ull(c, NULL, 10, &dev->wbps) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("could not parse write bytes sec %s"), c); - goto error; + return -1; } - VIR_FREE(c); } else if (virXMLNodeNameEqual(node, "read_iops_sec")) { - c =3D (char *)xmlNodeGetContent(node); if (virStrToLong_ui(c, NULL, 10, &dev->riops) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("could not parse read iops sec %s"), c); - goto error; + return -1; } - VIR_FREE(c); } else if (virXMLNodeNameEqual(node, "write_iops_sec")) { - c =3D (char *)xmlNodeGetContent(node); if (virStrToLong_ui(c, NULL, 10, &dev->wiops) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("could not parse write iops sec %s"), c); - goto error; + return -1; } - VIR_FREE(c); } } node =3D node->next; } - if (!dev->path) { + + if (!path) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("missing per-device path")); return -1; } =20 + dev->path =3D g_steal_pointer(&path); return 0; - - error: - VIR_FREE(dev->path); - return -1; } =20 =20 --=20 2.25.4