From nobody Fri Jan 3 02:36:26 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1729845152281870.1474615729619; Fri, 25 Oct 2024 01:32:32 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 40FC41BFC; Fri, 25 Oct 2024 04:32:31 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id A91431BDD; Fri, 25 Oct 2024 04:31:57 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 36C3F1AC1; Fri, 25 Oct 2024 04:31:54 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id BC567150C for ; Fri, 25 Oct 2024 04:31:53 -0400 (EDT) Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-608-RWNP67N6NXK5TcdUY1U0GQ-1; Fri, 25 Oct 2024 04:31:52 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 785871955D50 for ; Fri, 25 Oct 2024 08:31:51 +0000 (UTC) Received: from speedmetal.lan (unknown [10.45.242.4]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id AE4BC1955F22 for ; Fri, 25 Oct 2024 08:31:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729845113; h=from:from: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; bh=XE3OYAwjh2Ie/8YIxIv7+c7VQkiAF+bG1ERKS1VaKx4=; b=JlLtXBMojDk167fHnHh4lYraJOyJukePks28wTY63miAuTz4o9CBNfvdHkrvURldUbr3ZA Ejsa5Qbh7iKoyWxYCsmw8C8VS5l6lCBXYyzLVmDbTxyoivrCWKVLSfUESjG/ITeBwglZQL UZG3J6H0VoBxs53/MopP2Iz7l+dUWis= X-MC-Unique: RWNP67N6NXK5TcdUY1U0GQ-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 1/2] Replace improper use of g_malloc(0) with g_new0 Date: Fri, 25 Oct 2024 10:31:46 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: EQNPON5GGCYSKNLPDCZG2JPI4KBZY3B6 X-Message-ID-Hash: EQNPON5GGCYSKNLPDCZG2JPI4KBZY3B6 X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1729845153513116600 Content-Type: text/plain; charset="utf-8" Completely remove use of g_malloc (without zeroing of the allocated memory) and forbid further use. Replace use of g_malloc0 in cases where the variable holding the pointer has proper type. In all of the above cases we can use g_new0 instead. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- build-aux/syntax-check.mk | 4 ++-- src/util/virpcivpd.c | 6 +++--- tools/wireshark/src/packet-libvirt.c | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/build-aux/syntax-check.mk b/build-aux/syntax-check.mk index 0759372b2b..6ed2a61192 100644 --- a/build-aux/syntax-check.mk +++ b/build-aux/syntax-check.mk @@ -92,8 +92,8 @@ sc_prohibit_raw_virclassnew: # Avoid raw malloc and free, except in documentation comments. sc_prohibit_raw_allocation: - @prohibit=3D'^.[^*].*\<((m|c|re)alloc|free) *\([^)]' \ - halt=3D'use VIR_ macros from viralloc.h instead of malloc/free' \ + @prohibit=3D'^.[^*].*\<((m|c|re)alloc|free|g_malloc) *\([^)]' \ + halt=3D'use g_new0/g_malloc0/g_free instead of malloc/free/g_malloc' \ $(_sc_search_regexp) # Avoid functions that can lead to double-close bugs. diff --git a/src/util/virpcivpd.c b/src/util/virpcivpd.c index 02d405f038..688d1a3fcb 100644 --- a/src/util/virpcivpd.c +++ b/src/util/virpcivpd.c @@ -414,7 +414,7 @@ virPCIVPDParseVPDLargeResourceFields(int vpdFileFd, virPCIVPDResource *res) { /* A buffer of up to one resource record field size (plus a zero byte)= is needed. */ - g_autofree uint8_t *buf =3D g_malloc0(PCI_VPD_MAX_FIELD_SIZE + 1); + g_autofree uint8_t *buf =3D g_new0(uint8_t, PCI_VPD_MAX_FIELD_SIZE + 1= ); uint16_t fieldDataLen =3D 0, bytesToRead =3D 0; uint16_t fieldPos =3D resPos; bool hasChecksum =3D false; @@ -499,7 +499,7 @@ virPCIVPDParseVPDLargeResourceFields(int vpdFileFd, break; case VIR_PCI_VPD_RESOURCE_FIELD_VALUE_FORMAT_BINARY: - fieldValue =3D g_malloc(fieldDataLen); + fieldValue =3D g_new0(char, fieldDataLen); memcpy(fieldValue, buf, fieldDataLen); break; @@ -570,7 +570,7 @@ virPCIVPDParseVPDLargeResourceString(int vpdFileFd, uin= t16_t resPos, g_autofree char *resValue =3D NULL; /* The resource value is not NULL-terminated so add one more byte. */ - g_autofree char *buf =3D g_malloc0(resDataLen + 1); + g_autofree char *buf =3D g_new0(char, resDataLen + 1); if (virPCIVPDReadVPDBytes(vpdFileFd, (uint8_t *)buf, resDataLen, resPo= s, csum) < 0) return -1; diff --git a/tools/wireshark/src/packet-libvirt.c b/tools/wireshark/src/pac= ket-libvirt.c index ee20e3734d..da2aabd98a 100644 --- a/tools/wireshark/src/packet-libvirt.c +++ b/tools/wireshark/src/packet-libvirt.c @@ -166,7 +166,7 @@ dissect_xdr_opaque(tvbuff_t *tvb, proto_tree *tree, XDR= *xdrs, int hf, gboolean rc; guint8 *val; - val =3D g_malloc(size); + val =3D g_new0(guint8, size); start =3D xdr_getpos(xdrs); if ((rc =3D xdr_opaque(xdrs, (caddr_t)val, size))) { gint len =3D xdr_getpos(xdrs) - start; --=20 2.47.0 From nobody Fri Jan 3 02:36:26 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1729845166019266.66534152929876; Fri, 25 Oct 2024 01:32:46 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id E24DF150C; Fri, 25 Oct 2024 04:32:44 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 698F21BFB; Fri, 25 Oct 2024 04:32:00 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id DCDC51A2E; Fri, 25 Oct 2024 04:31:55 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 45F58150C for ; Fri, 25 Oct 2024 04:31:55 -0400 (EDT) Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-678-qy8RKe9BMcSWYYfsRfylRA-1; Fri, 25 Oct 2024 04:31:53 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id CBDEE1955F09 for ; Fri, 25 Oct 2024 08:31:52 +0000 (UTC) Received: from speedmetal.lan (unknown [10.45.242.4]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0641B1956056 for ; Fri, 25 Oct 2024 08:31:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729845115; h=from:from: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; bh=VgGgJNijmEQRKD27FlrceqRTgXCH+72aG5TeUztfMTk=; b=LVusXk3+pNv/rtM/+S9wZkLdrTkIWW7TA2VBSP/eivDsuCm5jc9tTmytHds3YEaDShKhnq vyCjx0ARUGSK3tn7NlUff6Zks/pRTSNDUnc7vJMLsPdAUUBXChqfAuf4zIgqtzlFF9P6nc srkt0s0F5zLsstLzUmu6b6qTQt0OgJs= X-MC-Unique: qy8RKe9BMcSWYYfsRfylRA-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 2/2] virstring: Use 'g_new0' instead of improper use of 'g_malloc0_n' Date: Fri, 25 Oct 2024 10:31:47 +0200 Message-ID: <929d49fb52d7b39a20b24e74001282a51b13c71b.1729845065.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: IB75NNKWIUBPYHJ6KICAMACJKCVVH5VM X-Message-ID-Hash: IB75NNKWIUBPYHJ6KICAMACJKCVVH5VM X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1729845167477116600 Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/util/virstring.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/util/virstring.c b/src/util/virstring.c index bc9b6cd40e..15c3f7bdd1 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -1078,12 +1078,10 @@ void virStringListRemoveDuplicates(char ***list) { size_t len =3D g_strv_length(*list); - char **unique; + char **unique =3D g_new0(char *, len + 1); size_t n =3D 0; size_t i; - unique =3D g_malloc0_n(len + 1, sizeof(char *)); - for (i =3D 0; i < len; i++) { if (n > 0 && STREQ_NULLABLE(unique[n - 1], (*list)[i])) g_free((*list)[i]); --=20 2.47.0