From nobody Sat Feb 7 04:40:29 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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=1620315100; cv=none; d=zohomail.com; s=zohoarc; b=XJJzwgIjAe15Nti3MiLH/KkoeiDcr9G+ST1KN+H11ndUWN2Go8TyZGDnOcUQu82hu4KcUeer2JrDj5KxITsUT8QhdNnIMB4z1Jh8GA0WafU+q9STSMdziC9/mbwaUbDe2YyoBjrSWWQGVoH9n8wufA3UyzyOVeEvzUxaj+Grm6k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620315100; 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=YNOPkVnnciN/e6wHBRmW7buoWEuEAdqOKqDj+yXy6Q8=; b=c4E+mMKLT3/j0lDZ1tzfIKQ0ChVjpdBOI50tlWGt2Yznrz1p+wghPWhMtB3CLaK19VqbASqByxxxhiKSQcnI6JJEmMfn1rzYqeogSar3hzQ0XxTfDeSObjucuQQPSxAmzjFZB8hkuzcXBys4aGiTUPQzeUHE0Aij9D9OugOCTek= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1620315100229992.914061990832; Thu, 6 May 2021 08:31:40 -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-421-Y9yl6hIaM5Cb5OMiQnsY9Q-1; Thu, 06 May 2021 11:31:30 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 762298049D8; Thu, 6 May 2021 15:31:21 +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 47C7C1059582; Thu, 6 May 2021 15:31:21 +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 069B755358; Thu, 6 May 2021 15:31:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 146FVJDM011403 for ; Thu, 6 May 2021 11:31:19 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9350E105C7E1; Thu, 6 May 2021 15:31:19 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.52]) by smtp.corp.redhat.com (Postfix) with ESMTP id DBC1C1079148 for ; Thu, 6 May 2021 15:31:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620315093; 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=YNOPkVnnciN/e6wHBRmW7buoWEuEAdqOKqDj+yXy6Q8=; b=bewOkST80LXed3AEJ6UTmpeB5WTfYZr3YT88qYqmQ73ZT2OT6IF7YXLObaSKxq9tr3zetV 4FVxN0p+p86YNdqMAJZ41ZF0SIacqG3jkMo8mnYCnKevGgGc/AmiQrjZD3IJGA+CS+0Pbx 7cHToKWL7RIMB0jR7LcG0uuy1ez1Om4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620315099; 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=YNOPkVnnciN/e6wHBRmW7buoWEuEAdqOKqDj+yXy6Q8=; b=SqyRas9MuDbxR08hUMwMrQcrm/WQzUMnjcis93zfbAv7N2UiZ0NmCMUOyPLxMCdHSC9byM S6jd4OgXyXTsLlwVaTe52CpW2D/lh8w/2gojpYrrBR4BGqfhjhzasacT5/YewSRwnlzdIk aqfequ/Bn7yix7vYboTaFypGiNrXTM4= X-MC-Unique: Y9yl6hIaM5Cb5OMiQnsY9Q-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 08/17] virXMLPropInt: Always initialize '@result' Date: Thu, 6 May 2021 17:31:00 +0200 Message-Id: <22113bbe4b50f2446e2b488c4d58f75abf7b6bbe.1620314826.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Compilers aren't able to see whether @result is set or not and thus don't warn of a potential use of uninitialized value. Always set @result to prevent uninitialized use. This is done by adding a @defaultResult argument to virXMLPropInt since many places have a non-0 default. In certain cases such as in virDomainControllerDefParseXML we pass the value from the original value, which will still trigger compiler checks if unused while preserving the existing functionality of keeping the previous value. This commit fixes 3 uses of uninitialized value parsed by this function: in virDomainDiskSourceNetworkParse introduced by 38dc25989c5 in virDomainChrSourceDefParseTCP introduced by fa48004af5b in virDomainGraphicsListenDefParseXML introduced by 0b20fd3754c Signed-off-by: Peter Krempa --- src/conf/domain_conf.c | 57 +++++++++++++++++++++--------------------- src/util/virxml.c | 6 ++++- src/util/virxml.h | 3 ++- 3 files changed, 36 insertions(+), 30 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 78775bb2b3..2bc2e55ee4 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -8221,7 +8221,7 @@ virDomainDiskSourceNetworkParse(xmlNodePtr node, if (flags & VIR_DOMAIN_DEF_PARSE_STATUS) { int value; if (virXMLPropInt(node, "tlsFromConfig", 10, VIR_XML_PROP_NONE, - &value) < 0) + &value, 0) < 0) return -1; src->tlsFromConfig =3D !!value; } @@ -9414,7 +9414,7 @@ virDomainControllerDefParseXML(virDomainXMLOption *xm= lopt, g_autofree xmlNodePtr *modelNodes =3D NULL; int nmodelNodes =3D 0; int numaNode =3D -1; - int ports =3D -1; + int ports; VIR_XPATH_NODE_AUTORESTORE(ctxt) int rc; g_autofree char *idx =3D NULL; @@ -9494,19 +9494,23 @@ virDomainControllerDefParseXML(virDomainXMLOption *= xmlopt, if (ntargetNodes =3D=3D 1) { if (def->type =3D=3D VIR_DOMAIN_CONTROLLER_TYPE_PCI) { if (virXMLPropInt(targetNodes[0], "chassisNr", 0, VIR_XML_PROP_NON= E, - &def->opts.pciopts.chassisNr) < 0) + &def->opts.pciopts.chassisNr, + def->opts.pciopts.chassisNr) < 0) return NULL; if (virXMLPropInt(targetNodes[0], "chassis", 0, VIR_XML_PROP_NONE, - &def->opts.pciopts.chassis) < 0) + &def->opts.pciopts.chassis, + def->opts.pciopts.chassis) < 0) return NULL; if (virXMLPropInt(targetNodes[0], "port", 0, VIR_XML_PROP_NONE, - &def->opts.pciopts.port) < 0) + &def->opts.pciopts.port, + def->opts.pciopts.port) < 0) return NULL; if (virXMLPropInt(targetNodes[0], "busNr", 0, VIR_XML_PROP_NONE, - &def->opts.pciopts.busNr) < 0) + &def->opts.pciopts.busNr, + def->opts.pciopts.busNr) < 0) return NULL; if (virXMLPropTristateSwitch(targetNodes[0], "hotplug", @@ -9515,7 +9519,8 @@ virDomainControllerDefParseXML(virDomainXMLOption *xm= lopt, return NULL; if ((rc =3D virXMLPropInt(targetNodes[0], "index", 0, VIR_XML_PROP= _NONE, - &def->opts.pciopts.targetIndex)) < 0) + &def->opts.pciopts.targetIndex, + def->opts.pciopts.targetIndex)) < 0) return NULL; if ((rc =3D=3D 1) && def->opts.pciopts.targetIndex =3D=3D -1) @@ -9548,7 +9553,7 @@ virDomainControllerDefParseXML(virDomainXMLOption *xm= lopt, return NULL; } - if ((rc =3D virXMLPropInt(node, "ports", 10, VIR_XML_PROP_NONE, &ports= )) < 0) + if ((rc =3D virXMLPropInt(node, "ports", 10, VIR_XML_PROP_NONE, &ports= , -1)) < 0) return NULL; if ((rc =3D=3D 1) && ports < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -9559,7 +9564,8 @@ virDomainControllerDefParseXML(virDomainXMLOption *xm= lopt, switch (def->type) { case VIR_DOMAIN_CONTROLLER_TYPE_VIRTIO_SERIAL: { if ((rc =3D virXMLPropInt(node, "vectors", 10, VIR_XML_PROP_NONE, - &def->opts.vioserial.vectors)) < 0) + &def->opts.vioserial.vectors, + def->opts.vioserial.vectors)) < 0) return NULL; if ((rc =3D=3D 1) && def->opts.vioserial.vectors < 0) { @@ -9630,7 +9636,8 @@ virDomainControllerDefParseXML(virDomainXMLOption *xm= lopt, break; case VIR_DOMAIN_CONTROLLER_TYPE_XENBUS: { if ((rc =3D virXMLPropInt(node, "maxGrantFrames", 10, VIR_XML_PROP= _NONE, - &def->opts.xenbusopts.maxGrantFrames)) < 0) + &def->opts.xenbusopts.maxGrantFrames, + def->opts.xenbusopts.maxGrantFrames)) < 0) return NULL; if ((rc =3D=3D 1) && def->opts.xenbusopts.maxGrantFrames < 0) { @@ -9641,7 +9648,8 @@ virDomainControllerDefParseXML(virDomainXMLOption *xm= lopt, } if ((rc =3D virXMLPropInt(node, "maxEventChannels", 10, VIR_XML_PR= OP_NONE, - &def->opts.xenbusopts.maxEventChannels)) <= 0) + &def->opts.xenbusopts.maxEventChannels, + def->opts.xenbusopts.maxEventChannels)) < = 0) return NULL; if ((rc =3D=3D 1) && def->opts.xenbusopts.maxEventChannels < 0) { @@ -11181,7 +11189,7 @@ virDomainChrSourceDefParseTCP(virDomainChrSourceDef= *def, int tmpVal; if (virXMLPropInt(source, "tlsFromConfig", 10, VIR_XML_PROP_NONE, - &tmpVal) < 0) + &tmpVal, 0) < 0) return -1; def->data.tcp.tlsFromConfig =3D !!tmpVal; } @@ -12376,7 +12384,7 @@ virDomainGraphicsListenDefParseXML(virDomainGraphic= sListenDef *def, if (flags & VIR_DOMAIN_DEF_PARSE_STATUS) { int tmp; - if (virXMLPropInt(node, "fromConfig", 10, VIR_XML_PROP_NONE, &tmp)= < 0) + if (virXMLPropInt(node, "fromConfig", 10, VIR_XML_PROP_NONE, &tmp,= 0) < 0) return -1; def->fromConfig =3D tmp !=3D 0; } @@ -12519,7 +12527,7 @@ virDomainGraphicsDefParseXMLVNC(virDomainGraphicsDe= f *def, } if (virXMLPropInt(node, "websocket", 10, VIR_XML_PROP_NONE, - &def->data.vnc.websocket) < 0) + &def->data.vnc.websocket, 0) < 0) return -1; if (websocketGenerated) @@ -12663,14 +12671,12 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphi= csDef *def, if (virDomainGraphicsListensParseXML(def, node, ctxt, flags) < 0) return -1; - def->data.spice.port =3D 0; if (virXMLPropInt(node, "port", 10, VIR_XML_PROP_NONE, - &def->data.spice.port) < 0) + &def->data.spice.port, 0) < 0) return -1; - def->data.spice.tlsPort =3D 0; if (virXMLPropInt(node, "tlsPort", 10, VIR_XML_PROP_NONE, - &def->data.spice.tlsPort) < 0) + &def->data.spice.tlsPort, 0) < 0) return -1; if (virXMLPropTristateBool(node, "autoport", VIR_XML_PROP_NONE, @@ -13527,7 +13533,6 @@ virDomainMemballoonDefParseXML(virDomainXMLOption *= xmlopt, virDomainMemballoonDef *def; VIR_XPATH_NODE_AUTORESTORE(ctxt) xmlNodePtr stats; - unsigned int period =3D 0; ctxt->node =3D node; @@ -13546,10 +13551,9 @@ virDomainMemballoonDefParseXML(virDomainXMLOption = *xmlopt, &def->free_page_reporting) < 0) goto error; - def->period =3D period; if ((stats =3D virXPathNode("./stats", ctxt))) { if (virXMLPropInt(stats, "period", 0, VIR_XML_PROP_NONE, - &def->period) < 0) + &def->period, 0) < 0) goto error; if (def->period < 0) @@ -14509,8 +14513,7 @@ virDomainRedirFilterUSBDevDefParseXML(xmlNodePtr no= de) def =3D g_new0(virDomainRedirFilterUSBDevDef, 1); - def->usbClass =3D -1; - if (virXMLPropInt(node, "class", 0, VIR_XML_PROP_NONE, &def->usbClass)= < 0) + if (virXMLPropInt(node, "class", 0, VIR_XML_PROP_NONE, &def->usbClass,= -1) < 0) return NULL; if (def->usbClass !=3D -1 && def->usbClass &~ 0xFF) { @@ -14519,12 +14522,10 @@ virDomainRedirFilterUSBDevDefParseXML(xmlNodePtr = node) return NULL; } - def->vendor =3D -1; - if (virXMLPropInt(node, "vendor", 0, VIR_XML_PROP_NONE, &def->vendor) = < 0) + if (virXMLPropInt(node, "vendor", 0, VIR_XML_PROP_NONE, &def->vendor, = -1) < 0) return NULL; - def->product =3D -1; - if (virXMLPropInt(node, "product", 0, VIR_XML_PROP_NONE, &def->product= ) < 0) + if (virXMLPropInt(node, "product", 0, VIR_XML_PROP_NONE, &def->product= , -1) < 0) return NULL; version =3D virXMLPropString(node, "version"); @@ -17868,7 +17869,7 @@ virDomainSchedulerParseCommonAttrs(xmlNodePtr node, if (*policy =3D=3D VIR_PROC_POLICY_FIFO || *policy =3D=3D VIR_PROC_POL= ICY_RR) { if (virXMLPropInt(node, "priority", 10, VIR_XML_PROP_REQUIRED, - priority) < 0) + priority, 0) < 0) return -1; } diff --git a/src/util/virxml.c b/src/util/virxml.c index a03cbf7265..449453121f 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -651,6 +651,7 @@ virXMLPropTristateSwitch(xmlNodePtr node, * @base: Number base, see strtol * @flags: Bitwise or of virXMLPropFlags * @result: The returned value + * @defaultResult: default value of @result in case the property is not fo= und * * Convenience function to return value of an integer attribute. * @@ -663,11 +664,14 @@ virXMLPropInt(xmlNodePtr node, const char *name, int base, virXMLPropFlags flags, - int *result) + int *result, + int defaultResult) { g_autofree char *tmp =3D NULL; int val; + *result =3D defaultResult; + if (!(tmp =3D virXMLPropString(node, name))) { if (!(flags & VIR_XML_PROP_REQUIRED)) return 0; diff --git a/src/util/virxml.h b/src/util/virxml.h index eb92fbf94e..939d2482cb 100644 --- a/src/util/virxml.h +++ b/src/util/virxml.h @@ -123,7 +123,8 @@ virXMLPropInt(xmlNodePtr node, const char *name, int base, virXMLPropFlags flags, - int *result) + int *result, + int defaultResult) ATTRIBUTE_NONNULL(0) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4); int --=20 2.30.2