From nobody Mon Feb 9 02:14:19 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=1600892082; cv=none; d=zohomail.com; s=zohoarc; b=im5SZo5jY120kkHG/rsaRvkEjIhzuimgOSIHeANwKM4Fs8sNKvRJWoaAYqxYQ0GlDNcgfyKHFFUedrGtcC4wh4Tw/Hx98wCvFCno923BQLLGVHyQQZJnjyDUHFHkhvxEy50Uqv979SR6XJjGyrliTekJn/pNXb8vEoaLENFEIoA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600892082; 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=HJCo1KB31MkOkzxPstZCeboAUc70CLY9J5vFb/SWX8E=; b=PdvZTXciVi5eaROQ+/y/ys76vMyvUoM4U86GYvTyLx80G6LrJV6wFOD29G7dBWiPeB9bko6bhDa/o+OmPsC2TqBEmqj2MZsjZ1p1EeTZj1x6LRcvzHSortTeCZBwW/1dxYU1wXHJLqnANPkWZdY3j96IdOpJxlsyMolEpPu82Cg= 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 1600892082021194.62769052924477; Wed, 23 Sep 2020 13:14:42 -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-269-Ch96HC9YPB6RIK7SkRpMmw-1; Wed, 23 Sep 2020 16:14:36 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1E2631891E8D; Wed, 23 Sep 2020 20:14:29 +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 F3E6478822; Wed, 23 Sep 2020 20:14:28 +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 BE450183D046; Wed, 23 Sep 2020 20:14:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 08NKBKm0028461 for ; Wed, 23 Sep 2020 16:11:20 -0400 Received: by smtp.corp.redhat.com (Postfix) id E17815D990; Wed, 23 Sep 2020 20:11:20 +0000 (UTC) Received: from hjs.redhat.com (unknown [10.43.2.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6A4335D98D for ; Wed, 23 Sep 2020 20:11:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600892080; 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=HJCo1KB31MkOkzxPstZCeboAUc70CLY9J5vFb/SWX8E=; b=YPzcx5DbrVXlEv+ky0GaxxOysB9QdskZ2LWVgHXQ9rIT2haxpsPQSpL84zSFHFvaPzH7co uj53hLxVfoZF4z4O2psS2PzVuXgWRKb51Rt0yjx2tOCh0/k3nZVNmztzwc/+rz2nyTCsmu gyPRRH90MPuCCBfgQ7bsgeC6OXDy8TE= X-MC-Unique: Ch96HC9YPB6RIK7SkRpMmw-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCH 4/5] security: use g_new0 instead of VIR_ALLOC* Date: Wed, 23 Sep 2020 22:11:07 +0200 Message-Id: <8bf956247a0b152e110f138061705a6f8977117f.1600891692.git.jtomko@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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.11 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Signed-off-by: J=C3=A1n Tomko Reviewed-by: Daniel Henrique Barboza --- src/security/security_apparmor.c | 3 +-- src/security/security_dac.c | 9 +++------ src/security/security_manager.c | 14 +++++--------- src/security/security_selinux.c | 9 +++------ src/security/security_stack.c | 6 ++---- 5 files changed, 14 insertions(+), 27 deletions(-) diff --git a/src/security/security_apparmor.c b/src/security/security_appar= mor.c index eea37dca83..c2d86c6940 100644 --- a/src/security/security_apparmor.c +++ b/src/security/security_apparmor.c @@ -867,8 +867,7 @@ AppArmorSetSecurityHostdevLabel(virSecurityManagerPtr m= gr, if (profile_loaded(secdef->imagelabel) < 0) return 0; =20 - if (VIR_ALLOC(ptr) < 0) - return -1; + ptr =3D g_new0(struct SDPDOP, 1); ptr->mgr =3D mgr; ptr->def =3D def; =20 diff --git a/src/security/security_dac.c b/src/security/security_dac.c index d9d4cda159..258d246659 100644 --- a/src/security/security_dac.c +++ b/src/security/security_dac.c @@ -108,8 +108,7 @@ virSecurityDACChownListAppend(virSecurityDACChownListPt= r list, char *tmp =3D NULL; virSecurityDACChownItemPtr item =3D NULL; =20 - if (VIR_ALLOC(item) < 0) - return -1; + item =3D g_new0(virSecurityDACChownItem, 1); =20 tmp =3D g_strdup(path); =20 @@ -227,8 +226,7 @@ virSecurityDACTransactionRun(pid_t pid G_GNUC_UNUSED, int ret =3D -1; =20 if (list->lock) { - if (VIR_ALLOC_N(paths, list->nItems) < 0) - return -1; + paths =3D g_new0(const char *, list->nItems); =20 for (i =3D 0; i < list->nItems; i++) { virSecurityDACChownItemPtr item =3D list->items[i]; @@ -580,8 +578,7 @@ virSecurityDACTransactionStart(virSecurityManagerPtr mg= r) return -1; } =20 - if (VIR_ALLOC(list) < 0) - return -1; + list =3D g_new0(virSecurityDACChownList, 1); =20 list->manager =3D virObjectRef(mgr); =20 diff --git a/src/security/security_manager.c b/src/security/security_manage= r.c index 17b565cc12..be81ee5e44 100644 --- a/src/security/security_manager.c +++ b/src/security/security_manager.c @@ -87,8 +87,7 @@ virSecurityManagerNewDriver(virSecurityDriverPtr drv, =20 virCheckFlags(VIR_SECURITY_MANAGER_NEW_MASK, NULL); =20 - if (VIR_ALLOC_N(privateData, drv->privateDataLen) < 0) - return NULL; + privateData =3D g_new0(char, drv->privateDataLen); =20 if (!(mgr =3D virObjectLockableNew(virSecurityManagerClass))) goto error; @@ -1034,8 +1033,7 @@ virSecurityManagerGetNested(virSecurityManagerPtr mgr) if (STREQ("stack", mgr->drv->name)) return virSecurityStackGetNested(mgr); =20 - if (VIR_ALLOC_N(list, 2) < 0) - return NULL; + list =3D g_new0(virSecurityManagerPtr, 2); =20 list[0] =3D mgr; list[1] =3D NULL; @@ -1346,9 +1344,8 @@ virSecurityManagerMetadataLock(virSecurityManagerPtr = mgr G_GNUC_UNUSED, const char **locked_paths =3D NULL; virSecurityManagerMetadataLockStatePtr ret =3D NULL; =20 - if (VIR_ALLOC_N(fds, npaths) < 0 || - VIR_ALLOC_N(locked_paths, npaths) < 0) - return NULL; + fds =3D g_new0(int, npaths); + locked_paths =3D g_new0(const char *, npaths); =20 /* Sort paths to lock in order to avoid deadlocks with other * processes. For instance, if one process wants to lock @@ -1441,8 +1438,7 @@ virSecurityManagerMetadataLock(virSecurityManagerPtr = mgr G_GNUC_UNUSED, VIR_APPEND_ELEMENT_COPY_INPLACE(fds, nfds, fd); } =20 - if (VIR_ALLOC(ret) < 0) - goto cleanup; + ret =3D g_new0(virSecurityManagerMetadataLockState, 1); =20 ret->paths =3D g_steal_pointer(&locked_paths); ret->fds =3D g_steal_pointer(&fds); diff --git a/src/security/security_selinux.c b/src/security/security_selinu= x.c index 87741d6dad..e40d670e97 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -123,8 +123,7 @@ virSecuritySELinuxContextListAppend(virSecuritySELinuxC= ontextListPtr list, int ret =3D -1; virSecuritySELinuxContextItemPtr item =3D NULL; =20 - if (VIR_ALLOC(item) < 0) - return -1; + item =3D g_new0(virSecuritySELinuxContextItem, 1); =20 item->path =3D g_strdup(path); item->tcon =3D g_strdup(tcon); @@ -258,8 +257,7 @@ virSecuritySELinuxTransactionRun(pid_t pid G_GNUC_UNUSE= D, int ret =3D -1; =20 if (list->lock) { - if (VIR_ALLOC_N(paths, list->nItems) < 0) - return -1; + paths =3D g_new0(const char *, list->nItems); =20 for (i =3D 0; i < list->nItems; i++) { virSecuritySELinuxContextItemPtr item =3D list->items[i]; @@ -1088,8 +1086,7 @@ virSecuritySELinuxTransactionStart(virSecurityManager= Ptr mgr) return -1; } =20 - if (VIR_ALLOC(list) < 0) - return -1; + list =3D g_new0(virSecuritySELinuxContextList, 1); =20 list->manager =3D virObjectRef(mgr); =20 diff --git a/src/security/security_stack.c b/src/security/security_stack.c index 2480c47f70..3bfcb1e2f7 100644 --- a/src/security/security_stack.c +++ b/src/security/security_stack.c @@ -56,8 +56,7 @@ virSecurityStackAddNested(virSecurityManagerPtr mgr, while (tmp && tmp->next) tmp =3D tmp->next; =20 - if (VIR_ALLOC(item) < 0) - return -1; + item =3D g_new0(virSecurityStackItem, 1); item->securityManager =3D nested; item->prev =3D tmp; if (tmp) @@ -620,8 +619,7 @@ virSecurityStackGetNested(virSecurityManagerPtr mgr) for (item =3D priv->itemsHead; item; item =3D item->next) len++; =20 - if (VIR_ALLOC_N(list, len + 1) < 0) - return NULL; + list =3D g_new0(virSecurityManagerPtr, len + 1); =20 for (i =3D 0, item =3D priv->itemsHead; item; item =3D item->next, i++) list[i] =3D item->securityManager; --=20 2.26.2