From nobody Sat May 4 11:18:26 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.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 205.139.110.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=1583401949; cv=none; d=zohomail.com; s=zohoarc; b=B/wZUYykUMgjvMqVYtLcHBu8wLeSrrxc8idgq+FDeYDPmo6zCPQMFrnJJdVTo0oMGLNhFB9MgYjMTqUL69gAhSCqSkbJRK0WE0hqRIKKdzK3rIyVaVXMK0GNCY6ctQrEcWwShlIfPi4+RG94EjeC3VNKXMzXJTgImbucDnZUxac= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583401949; 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=JRCOqjJUrbWT4/j6KOV3hmp2UmC/a+VfuEndxfjCpEs=; b=kx/mRUU/W+9cbWGSBUEU/3vi/f3Ur+ULysJxveKEeA83OUejLWcpC6a+8phZ76F5KDOMFehBgxaxPswQLWhqaynA976B/ilvLT+NvxBvbispnGmCAqELoEA2lq7ArAaCpF9LsYrvJo53OUR0iUpnI7wSe69Y/p3yBX1Z97AYvlQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.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 [205.139.110.120]) by mx.zohomail.com with SMTPS id 1583401949937222.95043200414273; Thu, 5 Mar 2020 01:52:29 -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-488-r0d-HE_ZOhmkm4CTJ71RQw-1; Thu, 05 Mar 2020 04:52:26 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B6C8B8014D8; Thu, 5 Mar 2020 09:52:17 +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 8348360CDA; Thu, 5 Mar 2020 09:52:17 +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 3377786A06; Thu, 5 Mar 2020 09:52:17 +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 0259q7Rf023321 for ; Thu, 5 Mar 2020 04:52:07 -0500 Received: by smtp.corp.redhat.com (Postfix) id A6C0B90779; Thu, 5 Mar 2020 09:52:07 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2CCD890538 for ; Thu, 5 Mar 2020 09:52:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583401948; 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=JRCOqjJUrbWT4/j6KOV3hmp2UmC/a+VfuEndxfjCpEs=; b=gQEsDJ2n72Jlcw72VDJb0gUgUHMpwZaNtOKBDqYVtcWDtxM5ofct38DLwblKb0jWXgiHXa 3/giBI93PH/RLeUzY6rwPgcdZkDyS0GNLn3EsrOxB2ikk02BDCeGTBY52kISecJcgSSXRh 8kyvwYln741VikQxs7tQ7keCebPpAdU= X-MC-Unique: r0d-HE_ZOhmkm4CTJ71RQw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 1/5] virNetworkPortDefSaveStatus: Fix potentially uninitialized 'path' by refactoring cleanup Date: Thu, 5 Mar 2020 10:51:58 +0100 Message-Id: <80124ad030bfa8daa46cb1b62548411122b27b55.1583401776.git.pkrempa@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.12 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" Use 'g_autofree' to clean both 'path' and 'xml' which mandates initialization and get rid of the 'cleanup' label and 'ret variable. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/conf/virnetworkportdef.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/conf/virnetworkportdef.c b/src/conf/virnetworkportdef.c index b58e2ccae0..a4cffea8b6 100644 --- a/src/conf/virnetworkportdef.c +++ b/src/conf/virnetworkportdef.c @@ -444,29 +444,24 @@ virNetworkPortDefSaveStatus(virNetworkPortDef *def, const char *dir) { char uuidstr[VIR_UUID_STRING_BUFLEN]; - char *path; - char *xml =3D NULL; - int ret =3D -1; + g_autofree char *path =3D NULL; + g_autofree char *xml =3D NULL; virUUIDFormat(def->uuid, uuidstr); if (virFileMakePath(dir) < 0) - goto cleanup; + return -1; if (!(path =3D virNetworkPortDefConfigFile(dir, uuidstr))) - goto cleanup; + return -1; if (!(xml =3D virNetworkPortDefFormat(def))) - goto cleanup; + return -1; if (virXMLSaveFile(path, uuidstr, "net-port-create", xml) < 0) - goto cleanup; + return -1; - ret =3D 0; - cleanup: - VIR_FREE(xml); - VIR_FREE(path); - return ret; + return 0; } --=20 2.24.1 From nobody Sat May 4 11:18:26 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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=1583401940; cv=none; d=zohomail.com; s=zohoarc; b=DmpWproxWIZT50hwiwb9HynhCjA3VQ8TVMU/cF9I54wHIitVySFHclL+eKAi1hA3aGCbfSWdOS1HzUKIAwj01Xpn1OzEpSYUTC4Il1BBNn7T+ZndkkC94Okey3YDImaU0oq+R/RU+ED/Ehg0qatp6RnLcvDoJa0SqcbY/KNTWzE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583401940; 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=bc5dEFzhDQnzAVZZbbVEOXkEvIdqhQlqT0+4Xnx9lbs=; b=BLVAPdD7hrkA7Lor6mbTKlY8jsCk49u73gN9hqLkrqxijSxqVY+fcqB+mzlnGf9m6zczQwCXdmpJiJz0zuDFHw0WrDW+K9p+cYxheMY0+hck+FEeaXC0SzcThR8M7yQFMWIvDjTpvZToiN/Osx4vhQCezLEDniQUvOvlphImG6E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1583401940337354.36847096815904; Thu, 5 Mar 2020 01:52: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-287-5G2xeFoVNYCsr3uLtLY3TQ-1; Thu, 05 Mar 2020 04:52:16 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3537D107ACCD; Thu, 5 Mar 2020 09:52:11 +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 CD23E19C6A; Thu, 5 Mar 2020 09:52: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 67C8D35AE1; Thu, 5 Mar 2020 09:52: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 0259q8Sx023326 for ; Thu, 5 Mar 2020 04:52:08 -0500 Received: by smtp.corp.redhat.com (Postfix) id 7AE5B90779; Thu, 5 Mar 2020 09:52:08 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 01F9F90538 for ; Thu, 5 Mar 2020 09:52:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583401939; 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=bc5dEFzhDQnzAVZZbbVEOXkEvIdqhQlqT0+4Xnx9lbs=; b=iLQfkGWixKDsZTfEI5MVifBgvNUwJmwDFYxtCA7NnPnA1e1S9M3Y7nXsUajjEeL/O55n8c F5CAjHQxzASNj7v5Qgb3U0BSbV+iZh6IHh/12AOxu6C11gYfr/vJSAJzHlB5t/WNjnlEgU 0mI+ckXTrtyXcluHX+JDBSmTde0nQ/o= X-MC-Unique: 5G2xeFoVNYCsr3uLtLY3TQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 2/5] virLXCProcessSetupNamespaceName: Fix potential uninitialized free of 'path' Date: Thu, 5 Mar 2020 10:51:59 +0100 Message-Id: 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.84 on 10.5.11.23 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" 'path' could be accessed uninitialized. Fix it by using g_autofree which also mandates initialization. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/lxc/lxc_process.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index 0277ba8b62..cd0026f78f 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -409,7 +409,7 @@ static int virLXCProcessSetupNamespaceName(virLXCDriver= Ptr driver, int fd =3D -1; virDomainObjPtr vm; virLXCDomainObjPrivatePtr priv; - char *path; + g_autofree char *path =3D NULL; vm =3D virDomainObjListFindByName(driver->domains, name); if (!vm) { @@ -436,7 +436,6 @@ static int virLXCProcessSetupNamespaceName(virLXCDriver= Ptr driver, } cleanup: - VIR_FREE(path); virDomainObjEndAPI(&vm); return fd; } --=20 2.24.1 From nobody Sat May 4 11:18:26 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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=1583401940; cv=none; d=zohomail.com; s=zohoarc; b=YiWSfj8LGmqTIaEn6eOKj1uY70Ykd2+P3y8a791xwd/KKAG9eUDcHVGLEyDHr2a4Bnq6xVQV0f4dm9LpuXoI0Kb5sSuN2Fdx3/zDILo58/5dFrCqu6eYdcuxBY+pf1ztY2g1m4jMP7EpTDzgFpl/p7yU/dWWbQldAiW5duEbCA8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583401940; 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=CNpFX/NI1YL5+hedaebys43qoNaiw9nD4xQzKKvxLas=; b=i5TrqWoaOO0doBtJzBI+MIp3TjN5FuD0uacvNxD8lMgQ4yTrhPQU2D9wZtO7AeCu9k+Y9VCWlp0drtrXU5NC27kDhoIODTfaRZMW4TjVcjOvBUQvSn/LF85xyPpHEvc3KA9YssxEb6IGCwFgnRbZeTKZMmCtfVjogRpiP6R11R4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1583401940412154.90292308441713; Thu, 5 Mar 2020 01:52: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-289-i713vjxRO7q4BsRXr2jn7A-1; Thu, 05 Mar 2020 04:52:17 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 500CB18FF660; Thu, 5 Mar 2020 09:52:12 +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 222815C1D8; Thu, 5 Mar 2020 09:52:12 +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 BCFCD35AE1; Thu, 5 Mar 2020 09:52:11 +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 0259q9sD023337 for ; Thu, 5 Mar 2020 04:52:09 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4EF2A90779; Thu, 5 Mar 2020 09:52:09 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id C9CD590538 for ; Thu, 5 Mar 2020 09:52:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583401939; 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=CNpFX/NI1YL5+hedaebys43qoNaiw9nD4xQzKKvxLas=; b=PhdFQ+w+0mUUNfgxp67KlqEasebxwsPsFdno//giNkyMKyB5Ivws5xUZwKelkRCcDIcJq0 58KPCNRzalBksfWkTI1WIw5BxuGtvPhM7kxrHo82Lp89IfbCIwXht4md1ZJeWVJCdwa5Y3 3Xt41suyhBroNdn1D5F4KU+E/T6LDJc= X-MC-Unique: i713vjxRO7q4BsRXr2jn7A-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 3/5] cmdDomHostname: Fix uninitialized use of 'hostname' by refactoring cleanup Date: Thu, 5 Mar 2020 10:52:00 +0100 Message-Id: <9b43aec200e8ddc277b96afbf9f38fed443e89f8.1583401776.git.pkrempa@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.16 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" Use 'g_autoptr' which mandates initialization for 'hostname' and also for 'domain' to allow full refactor of the cleanup path. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- tools/virsh-domain.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 9d0f7d68d2..8591e483a5 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -11885,9 +11885,8 @@ VIR_ENUM_IMPL(virshDomainHostnameSource, static bool cmdDomHostname(vshControl *ctl, const vshCmd *cmd) { - char *hostname; - virDomainPtr dom; - bool ret =3D false; + g_autofree char *hostname =3D NULL; + g_autoptr(virshDomain) dom =3D NULL; const char *sourcestr =3D NULL; int flags =3D 0; /* Use default value. Drivers can have its own defaul= t. */ @@ -11895,14 +11894,14 @@ cmdDomHostname(vshControl *ctl, const vshCmd *cmd) return false; if (vshCommandOptStringReq(ctl, cmd, "source", &sourcestr) < 0) - goto error; + return false; if (sourcestr) { int source =3D virshDomainHostnameSourceTypeFromString(sourcestr); if (source < 0) { vshError(ctl, _("Unknown data source '%s'"), sourcestr); - goto error; + return false; } switch ((virshDomainHostnameSource) source) { @@ -11920,16 +11919,11 @@ cmdDomHostname(vshControl *ctl, const vshCmd *cmd) hostname =3D virDomainGetHostname(dom, flags); if (hostname =3D=3D NULL) { vshError(ctl, "%s", _("failed to get hostname")); - goto error; + return false; } vshPrint(ctl, "%s\n", hostname); - ret =3D true; - - error: - VIR_FREE(hostname); - virshDomainFree(dom); - return ret; + return true; } /** --=20 2.24.1 From nobody Sat May 4 11:18:26 2024 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=1583401983; cv=none; d=zohomail.com; s=zohoarc; b=BHRuJ6f5Tgeikj6HEzBNgv4rQWVjN2ATwZi+PQcmUIS6mUHx1blbfaRk6S6UoXfb+z2XoRC5Zf43joF3Fg/VWrOWKifL0Hsqo1HNXa1huMqxUduRKlyjqMwe1lCf3j3p+Vk0pBiYhvzok7qQsl3Nd+dTFL+LPJ1qQ0vrlMp5wqc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583401983; 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=xFZtpdKuhhths5q4jGh6vFidb/RlPi3zBW6jcNWByMQ=; b=Eqmmkn9GTW6oGiekfeot387KzaE/FCa+V7gsa35quchU994DM3VOTruq7LEu7jCJ9CBeJ3j+BN3gg4ZEh9Ve4BljU926KP2EXMxm5nICJ2tZhjyn7cDRKNQ91sr/eeb3ADi/o1eZGUhAkPgERYigWvYNpMtSwycEbamXellfH/8= 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 1583401983409893.794818231999; Thu, 5 Mar 2020 01:53:03 -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-473-DsY2qiT6Miii9kPJACll9g-1; Thu, 05 Mar 2020 04:52:27 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1AD6118FF665; Thu, 5 Mar 2020 09:52:22 +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 8E90060BE0; Thu, 5 Mar 2020 09:52: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 42DD818089CE; Thu, 5 Mar 2020 09:52:21 +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 0259qAwo023345 for ; Thu, 5 Mar 2020 04:52:10 -0500 Received: by smtp.corp.redhat.com (Postfix) id 22B2891D8A; Thu, 5 Mar 2020 09:52:10 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9D40A90538 for ; Thu, 5 Mar 2020 09:52:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583401982; 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=xFZtpdKuhhths5q4jGh6vFidb/RlPi3zBW6jcNWByMQ=; b=DuFk6RnLSYAVGaJ1I5rxLKaImll5JcEriVa7jn7ZheGTp7bv+mrVis3v9oNZHFb6ssHPQ+ Via/K+A0lj4iQEazNMWEhUz1F2R6jiZfJTGYJDPV+5YMXDvjPCYp5z5sAr2u/iSU6SMQo3 GI1wb4OOyxAW6ydUYLskQBA4F8+isXk= X-MC-Unique: DsY2qiT6Miii9kPJACll9g-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 4/5] testQemuMonitorJSONqemuMonitorJSONGetTargetArch: Fix uninitialized use of 'arch' Date: Thu, 5 Mar 2020 10:52:01 +0100 Message-Id: <8226ba2e627126961749c6a4623405814c935872.1583401776.git.pkrempa@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.12 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" Refactor the cleanup control flow and use g_autofree for 'arch' so that it's mandated that it's initialized. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- tests/qemumonitorjsontest.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index e9f95e317d..c7049bcdf0 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -2162,8 +2162,7 @@ testQemuMonitorJSONqemuMonitorJSONGetTargetArch(const= void *opaque) { const testGenericData *data =3D opaque; virDomainXMLOptionPtr xmlopt =3D data->xmlopt; - int ret =3D -1; - char *arch; + g_autofree char *arch =3D NULL; g_autoptr(qemuMonitorTest) test =3D NULL; if (!(test =3D qemuMonitorTestNewSchema(xmlopt, data->schema))) @@ -2176,22 +2175,19 @@ testQemuMonitorJSONqemuMonitorJSONGetTargetArch(con= st void *opaque) " }," " \"id\": \"libvirt-21\"" "}") < 0) - goto cleanup; + return -1; if (!(arch =3D qemuMonitorJSONGetTargetArch(qemuMonitorTestGetMonitor(= test)))) - goto cleanup; + return -1; if (STRNEQ(arch, "x86_64")) { virReportError(VIR_ERR_INTERNAL_ERROR, "Unexpected architecture %s, expecting x86_64", arch); - goto cleanup; + return -1; } - ret =3D 0; - cleanup: - VIR_FREE(arch); - return ret; + return 0; } static int --=20 2.24.1 From nobody Sat May 4 11:18:26 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.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 205.139.110.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=1583401955; cv=none; d=zohomail.com; s=zohoarc; b=csteHpwdVae0MoaR43m4Nxca/VXMN8tGF19gHR/+fy+bHiboViUcqt92iQ/uinAFth3KgauCj9/obVuK+A5zqbWFDa9MXLI+DskAmY9AZPSXmwPPd9YyRJE81ztj+tk3oMLnduR0KoNdOclFK2pZijA9ahhIgk+PtsbhcJ+cp8E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583401955; 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=SSBjKdpzN+QzrlqMfin/rpI7rQY3h7LUJEBbl7HOhx4=; b=Z/DWpX0tGlJw7i4v6ADKv6aAFThH2CQkPEIIFlxTf4uI4DKi1awP7l+r2IQemV02MpfEqASnIl0kzrs6FJ++UojDmVtNKBzEIk+HI/kR1/CaT+hfsiw9RT5qYKwMcDSrmXLiz0qZOHqTsfGyFs4PHqpfqTpCxwr1p+Cd0iXnifA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.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 [205.139.110.120]) by mx.zohomail.com with SMTPS id 1583401955742130.71426952312822; Thu, 5 Mar 2020 01:52:35 -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-472-QILL9owtOROLCQcAGRr5Dw-1; Thu, 05 Mar 2020 04:52:31 -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 DE0EB8018A5; Thu, 5 Mar 2020 09:52:25 +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 B079B90779; Thu, 5 Mar 2020 09:52:25 +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 55EEB18089D5; Thu, 5 Mar 2020 09:52:25 +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 0259qA7F023352 for ; Thu, 5 Mar 2020 04:52:10 -0500 Received: by smtp.corp.redhat.com (Postfix) id EAAEB90538; Thu, 5 Mar 2020 09:52:10 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7237291D71 for ; Thu, 5 Mar 2020 09:52:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583401954; 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=SSBjKdpzN+QzrlqMfin/rpI7rQY3h7LUJEBbl7HOhx4=; b=BXGQB2gbR2pnT4oapGal2dLF9r4YfLJFrhLZ6OQd8M00EnjVWkYappp4eMrsUvMuhYULey Z4ztTY/sPvblZ0kQ91KlfI+9JU0SvI+oP0Krxdmje9HhE27r3AimGszPuy2SGkuzgxeJIx HxJOczi1NfUy0w43ld1UbAknY928lrk= X-MC-Unique: QILL9owtOROLCQcAGRr5Dw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 5/5] VIR_ALLOC: Replace internals by g_clear_pointer Date: Thu, 5 Mar 2020 10:52:02 +0100 Message-Id: <341c26e59b5dbf0e72f03f8f39d82f5417e43cf2.1583401776.git.pkrempa@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 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" Our implementation masks GCC warnings of uninitialized use of the passed argument. After changing this I got a load of following warnings: src/conf/virnetworkportdef.c: In function 'virNetworkPortDefSaveStatus': /usr/include/glib-2.0/glib/gmem.h:136:8: error: 'path' may be used uninitia= lized in this function [-Werror=3Dmaybe-uninitialized] 136 | if (_p) \ | ^ src/conf/virnetworkportdef.c:447:11: note: 'path' was declared here 447 | char *path; | ^~~~ For the curious, g_clear_pointer is still safe for arguments with side-effect. Here's the post-processed output of trying to do a VIR_FREE(*(test2++)): do { typedef char _GStaticAssertCompileTimeAssertion_1[(sizeof *(&(*(test2+= +))) =3D=3D sizeof (gpointer)) ? 1 : -1] __attribute__((__unused__)); __typeof__((&(*(test2++)))) _pp =3D (&(*(test2++))); __typeof__(*(&(*(test2++)))) _ptr =3D *_pp; *_pp =3D ((void *)0); if (_ptr) (g_free) (_ptr); } while (0) ; Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/libvirt_private.syms | 1 - src/util/viralloc.c | 21 ++------------------- src/util/viralloc.h | 7 +------ 3 files changed, 3 insertions(+), 26 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 8563695c32..d5f6d7ec05 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1584,7 +1584,6 @@ virDeleteElementsN; virDispose; virDisposeString; virExpandN; -virFree; virInsertElementsN; virReallocN; virResizeN; diff --git a/src/util/viralloc.c b/src/util/viralloc.c index b8ca850764..e254416cdf 100644 --- a/src/util/viralloc.c +++ b/src/util/viralloc.c @@ -178,7 +178,8 @@ void virShrinkN(void *ptrptr, size_t size, size_t *coun= tptr, size_t toremove) if (virReallocN(ptrptr, size, *countptr -=3D toremove) < 0) abort(); } else { - virFree(ptrptr); + g_free(*((void **)ptrptr)); + *((void **)ptrptr) =3D NULL; *countptr =3D 0; } } @@ -333,24 +334,6 @@ int virAllocVar(void *ptrptr, } -/** - * virFree: - * @ptrptr: pointer to pointer for address of memory to be freed - * - * Release the chunk of memory in the pointer pointed to by - * the 'ptrptr' variable. After release, 'ptrptr' will be - * updated to point to NULL. - */ -void virFree(void *ptrptr) -{ - int save_errno =3D errno; - - g_free(*(void**)ptrptr); - *(void**)ptrptr =3D NULL; - errno =3D save_errno; -} - - /** * virDispose: * @ptrptr: pointer to pointer for address of memory to be sanitized and f= reed diff --git a/src/util/viralloc.h b/src/util/viralloc.h index 1d42aeead1..833f85f62e 100644 --- a/src/util/viralloc.h +++ b/src/util/viralloc.h @@ -55,7 +55,6 @@ int virDeleteElementsN(void *ptrptr, size_t size, size_t = at, size_t *countptr, ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4); int virAllocVar(void *ptrptr, size_t struct_size, size_t element_size, siz= e_t count) G_GNUC_WARN_UNUSED_RESULT ATTRIBUTE_NONNULL(1); -void virFree(void *ptrptr) ATTRIBUTE_NONNULL(1); void virDispose(void *ptrptr, size_t count, size_t element_size, size_t *c= ountptr) ATTRIBUTE_NONNULL(1); @@ -417,11 +416,7 @@ void virDisposeString(char **strptr) * * This macro is safe to use on arguments with side effects. */ -/* The ternary ensures that ptr is a non-const pointer and not an - * integer type, all while evaluating ptr only once. This gives us - * extra compiler safety when compiling under gcc. - */ -#define VIR_FREE(ptr) virFree(1 ? (void *) &(ptr) : (ptr)) +#define VIR_FREE(ptr) g_clear_pointer(&(ptr), g_free) /** --=20 2.24.1