From nobody Fri May 3 11:35:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1612885398; cv=none; d=zohomail.com; s=zohoarc; b=hXbv59J6WaEeBWaDtFlHuRRh8fbBYTIu6O86x+8QxaGXNgPz2J4VPteIE5j0Q+5lZlm1KsDgOsqcOJM8IZriyS/FAbuXc1hbw6zW+ucsQOqvgW2FGWUnQiEGO0+julmTE2C5xIs4nrnb2Nzl4h4ezUHxtu7VJxUDmmVfi1YoSlY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612885398; 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=Lo8FalGNs9WqPmpf82iiz01U9aYv7/lA8P42nRkNaw4=; b=l0PhyYF2NDsaM9zWZgxqhOsrVgSV+OGaE22TSfwD9goabcFlgreC904wJl/tV4Y8XLWhSYwlM1pypwz4XZLKdhcUTEo1crOAleHz28oHLoQ14Ed1s9DeQS2jIEZHmCO3AMwTJlxB9SOWKG4eLgHAjlJeJgYmX9YTxbY1H769vso= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 1612885398294469.08164370159454; Tue, 9 Feb 2021 07:43:18 -0800 (PST) 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-446-ZPdrLTrAM3umT1OXCEk3Qg-1; Tue, 09 Feb 2021 10:43:13 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 177F080196C; Tue, 9 Feb 2021 15:43:07 +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 E7FB160C5E; Tue, 9 Feb 2021 15:43:06 +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 A9B8950033; Tue, 9 Feb 2021 15:43:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 119FgiZf007897 for ; Tue, 9 Feb 2021 10:42:44 -0500 Received: by smtp.corp.redhat.com (Postfix) id C40A360861; Tue, 9 Feb 2021 15:42:44 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.195.5]) by smtp.corp.redhat.com (Postfix) with ESMTP id 45D7160C5E for ; Tue, 9 Feb 2021 15:42:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612885397; 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=Lo8FalGNs9WqPmpf82iiz01U9aYv7/lA8P42nRkNaw4=; b=c9LoKL/02a1cwM0v9uSmtEWGeCq4ndCxp0efchCHAhrFyPn9ZWSPO85EV0pp0n7gPq8WvI 6Tx6/H/Ee1RltWMb74kgW1h1bzze3aUZ9vloRtrxiRGF3KF2Xw5FA+b8fHQR/+e3sxTM5j 8j8pTR4eYddb62TG2qSpw5wfKy1sdQg= X-MC-Unique: ZPdrLTrAM3umT1OXCEk3Qg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 1/2] qemu_capabilities: Don't leak @str in virQEMUCapsLoadMachines() Date: Tue, 9 Feb 2021 16:42:37 +0100 Message-Id: <0fdcf880c89747f2bef7105db7c1a2314b50a197.1612885330.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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.13 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) Content-Type: text/plain; charset="utf-8" If parsing "maxCpus" attribute of element fails an error is printed but the corresponding string is not freed. While it is very unlikely to happen (parsed XML is not user provided and we are the ones generating it), it is possible. Instead of freeing the variable in the error path explicitly, let's declare it as g_autofree. And while I'm at it, let's bring it into the loop where it's used. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_capabilities.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index d41b4a4753..4a6ef2e383 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -4012,7 +4012,6 @@ virQEMUCapsLoadMachines(virQEMUCapsAccelPtr caps, { g_autofree char *xpath =3D g_strdup_printf("./machine[@type=3D'%s']", = typeStr); g_autofree xmlNodePtr *nodes =3D NULL; - char *str =3D NULL; size_t i; int n; =20 @@ -4029,6 +4028,8 @@ virQEMUCapsLoadMachines(virQEMUCapsAccelPtr caps, caps->machineTypes =3D g_new0(virQEMUCapsMachineType, caps->nmachineTy= pes); =20 for (i =3D 0; i < n; i++) { + g_autofree char *str =3D NULL; + if (!(caps->machineTypes[i].name =3D virXMLPropString(nodes[i], "n= ame"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing machine name in QEMU capabilities ca= che")); --=20 2.26.2 From nobody Fri May 3 11:35:20 2024 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=1612885400; cv=none; d=zohomail.com; s=zohoarc; b=bl0GL3cFHIhG9FF1r9mHctagKlC3pmf5/upHkdE8f8Qferb5McHIAU4JWRe18MKgn/YxJ7lpaetvTRMTo9D5ktvKyeWYQmVXDn+iJXJ6KOXXw7fQPyYuUiAOo9S4TpDUWk+P/bnzcH1D4gRuZDFw7lAhiUWG7tYwk2zKJosey0E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612885400; 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=Hahvxqw6xrsTZKvGO/v4MG+6wdu4i1SaVaSprWgEzJg=; b=geNq1BH5benAq3t5S345KIB6N7gacBFmaEWIxiP0B+k46z7emMN2UdX1us3xPxSjLS/tDjDMMSP9ik2c8yDOZHU0fOMzhB0m5/3+qwkcw1CamhxncgtVMFfAwcpGB9SrRFRo6O8Y6B3EEmnVuXNdEcNDnTw7E47Jl0iHbUSdvBM= 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 161288540031919.32080101042459; Tue, 9 Feb 2021 07:43:20 -0800 (PST) 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-361-ctki5Wm_Oe2kvffZ5MvWHw-1; Tue, 09 Feb 2021 10:43:16 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B789D107ACE6; Tue, 9 Feb 2021 15:43:10 +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 877A960C5E; Tue, 9 Feb 2021 15:43:10 +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 3CB4A18095CE; Tue, 9 Feb 2021 15:43:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 119Fgj35007903 for ; Tue, 9 Feb 2021 10:42:45 -0500 Received: by smtp.corp.redhat.com (Postfix) id A126E1412A; Tue, 9 Feb 2021 15:42:45 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.195.5]) by smtp.corp.redhat.com (Postfix) with ESMTP id 214BD60861 for ; Tue, 9 Feb 2021 15:42:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612885399; 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=Hahvxqw6xrsTZKvGO/v4MG+6wdu4i1SaVaSprWgEzJg=; b=FPhvWwTG2AYx888Pg2bMHQsDZ5DKK8S/yvqemXK/51lDly/5LvzxZElQthQ3OXC7aBYwZc OtK9qcYs3Zgb4r2ZmChRVlHWsasuHXdwMTLwm0PEHskvY2lbYuektIXp+APWyDjlu7s3TL DoXoWQYdeqd+CAQdlKcE6+QoydUWr1E= X-MC-Unique: ctki5Wm_Oe2kvffZ5MvWHw-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 2/2] qemu_capabilities: Parse "deprecated" in virQEMUCapsLoadMachines() properly Date: Tue, 9 Feb 2021 16:42:38 +0100 Message-Id: <42c8ec991e80d9fdfbae90aa56272b31554e9589.1612885330.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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.13 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) Content-Type: text/plain; charset="utf-8" A element can have "deprecated" attribute that corresponds to 'deprecated' member of _virQEMUCapsMachineType struct. But the member is of boolean type. Therefore, the string returned by virXMLPropString() must be freed. Signed-off-by: Michal Privoznik Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_capabilities.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 4a6ef2e383..ebd6607888 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -4063,7 +4063,11 @@ virQEMUCapsLoadMachines(virQEMUCapsAccelPtr caps, =20 caps->machineTypes[i].defaultCPU =3D virXMLPropString(nodes[i], "d= efaultCPU"); caps->machineTypes[i].defaultRAMid =3D virXMLPropString(nodes[i], = "defaultRAMid"); - caps->machineTypes[i].deprecated =3D virXMLPropString(nodes[i], "d= eprecated"); + + str =3D virXMLPropString(nodes[i], "deprecated"); + if (STREQ_NULLABLE(str, "yes")) + caps->machineTypes[i].deprecated =3D true; + VIR_FREE(str); } =20 return 0; --=20 2.26.2