From nobody Sun Feb 8 09:41:09 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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 (zoho.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=1571576229; cv=none; d=zoho.com; s=zohoarc; b=ED6zXZWsRLbTtHs15OKLmK3o62733FRSmBjt9MlUxi5WdmvoeUgwAY/Zl6s1GncZ3zAvPWnA3SZSSaaWhVmrVqyH/GSE92SsmrhBDuFIgqnojhYNMG5WBvcEOAL3GJ1LMnSgGkQVrvE6cXCOuIypj410ly71uU9cg5PE26XQRPs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571576229; 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=wNEutdq3twecgfxLlsb0UWSgvEHpnZeR91TzKZwPoxQ=; b=YrLqARTvDVczXIFC+O2RIqI3YjYxq5NkXhAZ5qLvhJUxqlbWCCgsQwQ1oWDZwKb1YtVx66u46SSp42ESOEI3QewPho0Sbtqp0+Bsy6wEtmb0rLnTM2sVg4FXNEAD/kbMOF251AG/Y4Io6hZhjFPamXfhWzl+rJ4zYgaUYUOd/2A= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.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 15715762292529.050854817202776; Sun, 20 Oct 2019 05:57:09 -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-226-ENoC311MM9mzukZnu39Z8w-1; Sun, 20 Oct 2019 08:56:35 -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 1D4985FB; Sun, 20 Oct 2019 12:56:26 +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 E90AC600CE; Sun, 20 Oct 2019 12:56: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 8454D4EEBA; Sun, 20 Oct 2019 12:56:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9KCu3JY023559 for ; Sun, 20 Oct 2019 08:56:03 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7D5D33CC8; Sun, 20 Oct 2019 12:56:03 +0000 (UTC) Received: from lpt.redhat.com (ovpn-200-23.brq.redhat.com [10.40.200.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id CF141194B9 for ; Sun, 20 Oct 2019 12:56:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571576228; 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=wNEutdq3twecgfxLlsb0UWSgvEHpnZeR91TzKZwPoxQ=; b=a9WKkNrFdwIe58x5s+DEhAiA25Ucfm9RyF7hO2pdBXhXSdgAOMjQyrGepbVFDfnZoYGNHL FlzY4WA6L+ZtgLSx0HbQHZE/uJ/FiIoVhnDUoQEGe0neg1ckU4UugDONT68J2xKCozDDbC FmLio59PYD4ixziOPbOFCryHWbREJ5E= From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Sun, 20 Oct 2019 14:55:43 +0200 Message-Id: <2a5d1c450aee2ba6eecac23b97b4fd670e7b59f6.1571575890.git.jtomko@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 25/34] security: use g_strdup instead of VIR_STRDUP 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 X-MC-Unique: ENoC311MM9mzukZnu39Z8w-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Replace all occurrences of if (VIR_STRDUP(a, b) < 0) /* effectively dead code */ with: a =3D g_strdup(b); Signed-off-by: J=C3=A1n Tomko --- src/security/security_apparmor.c | 6 ++---- src/security/security_dac.c | 10 +++------ src/security/security_selinux.c | 37 +++++++++++--------------------- src/security/virt-aa-helper.c | 15 +++++-------- 4 files changed, 23 insertions(+), 45 deletions(-) diff --git a/src/security/security_apparmor.c b/src/security/security_appar= mor.c index 82826d193c..9ad218b383 100644 --- a/src/security/security_apparmor.c +++ b/src/security/security_apparmor.c @@ -452,12 +452,10 @@ AppArmorGenSecurityLabel(virSecurityManagerPtr mgr G_= GNUC_UNUSED, if ((profile_name =3D get_profile_name(def)) =3D=3D NULL) return rc; =20 - if (VIR_STRDUP(secdef->label, profile_name) < 0) - goto cleanup; + secdef->label =3D g_strdup(profile_name); =20 /* set imagelabel the same as label (but we won't use it) */ - if (VIR_STRDUP(secdef->imagelabel, profile_name) < 0) - goto err; + secdef->imagelabel =3D g_strdup(profile_name); =20 if (!secdef->model) secdef->model =3D g_strdup(SECURITY_APPARMOR_NAME); diff --git a/src/security/security_dac.c b/src/security/security_dac.c index 5d975f5903..4f646bc3b7 100644 --- a/src/security/security_dac.c +++ b/src/security/security_dac.c @@ -111,8 +111,7 @@ virSecurityDACChownListAppend(virSecurityDACChownListPt= r list, if (VIR_ALLOC(item) < 0) return -1; =20 - if (VIR_STRDUP(tmp, path) < 0) - goto cleanup; + tmp =3D g_strdup(path); =20 item->path =3D tmp; item->src =3D src; @@ -2311,11 +2310,8 @@ virSecurityDACGenLabel(virSecurityManagerPtr mgr, return rc; } =20 - if (seclabel->relabel && !seclabel->imagelabel && - VIR_STRDUP(seclabel->imagelabel, seclabel->label) < 0) { - VIR_FREE(seclabel->label); - return rc; - } + if (seclabel->relabel && !seclabel->imagelabel) + seclabel->imagelabel =3D g_strdup(seclabel->label); =20 return 0; } diff --git a/src/security/security_selinux.c b/src/security/security_selinu= x.c index c24a63afd6..d80ec01c5d 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -130,8 +130,8 @@ virSecuritySELinuxContextListAppend(virSecuritySELinuxC= ontextListPtr list, if (VIR_ALLOC(item) < 0) return -1; =20 - if (VIR_STRDUP(item->path, path) < 0 || VIR_STRDUP(item->tcon, tcon) <= 0) - goto cleanup; + item->path =3D g_strdup(path); + item->tcon =3D g_strdup(tcon); =20 item->remember =3D remember; item->restore =3D restore; @@ -444,8 +444,7 @@ virSecuritySELinuxMCSGetProcessRange(char **sens, if (!(contextRange =3D context_range_get(ourContext))) contextRange =3D "s0"; =20 - if (VIR_STRDUP(*sens, contextRange) < 0) - goto cleanup; + *sens =3D g_strdup(contextRange); =20 /* Find and blank out the category part (if any) */ tmp =3D strchr(*sens, ':'); @@ -622,8 +621,7 @@ virSecuritySELinuxGenNewContext(const char *basecontext, _("Unable to format SELinux context")); goto cleanup; } - if (VIR_STRDUP(ret, str) < 0) - goto cleanup; + ret =3D g_strdup(str); VIR_DEBUG("Generated context '%s'", ret); cleanup: freecon(ourSecContext); @@ -740,8 +738,7 @@ virSecuritySELinuxQEMUInitialize(virSecurityManagerPtr = mgr) *ptr =3D '\0'; ptr++; if (*ptr !=3D '\0') { - if (VIR_STRDUP(data->alt_domain_context, ptr) < 0) - goto error; + data->alt_domain_context =3D g_strdup(ptr); ptr =3D strchrnul(data->alt_domain_context, '\n'); if (ptr && *ptr =3D=3D '\n') *ptr =3D '\0'; @@ -761,8 +758,7 @@ virSecuritySELinuxQEMUInitialize(virSecurityManagerPtr = mgr) ptr =3D strchrnul(data->file_context, '\n'); if (ptr && *ptr =3D=3D '\n') { *ptr =3D '\0'; - if (VIR_STRDUP(data->content_context, ptr + 1) < 0) - goto error; + data->content_context =3D g_strdup(ptr + 1); ptr =3D strchrnul(data->content_context, '\n'); if (ptr && *ptr =3D=3D '\n') *ptr =3D '\0'; @@ -868,8 +864,7 @@ virSecuritySELinuxGenLabel(virSecurityManagerPtr mgr, virReportSystemError(errno, "%s", _("unable to get selinux con= text range")); goto cleanup; } - if (VIR_STRDUP(mcs, range) < 0) - goto cleanup; + mcs =3D g_strdup(range); break; =20 case VIR_DOMAIN_SECLABEL_DYNAMIC: @@ -919,8 +914,7 @@ virSecuritySELinuxGenLabel(virSecurityManagerPtr mgr, &catMax) < 0) goto cleanup; =20 - if (VIR_STRDUP(mcs, sens) < 0) - goto cleanup; + mcs =3D g_strdup(sens); =20 break; =20 @@ -2214,8 +2208,7 @@ virSecuritySELinuxSetHostdevCapsLabel(virSecurityMana= gerPtr mgr, dev->source.caps.u.storage.block) < 0) return -1; } else { - if (VIR_STRDUP(path, dev->source.caps.u.storage.block) < 0) - return -1; + path =3D g_strdup(dev->source.caps.u.storage.block); } ret =3D virSecuritySELinuxSetFilecon(mgr, path, secdef->imagelabel= , true); VIR_FREE(path); @@ -2228,8 +2221,7 @@ virSecuritySELinuxSetHostdevCapsLabel(virSecurityMana= gerPtr mgr, dev->source.caps.u.misc.chardev) < 0) return -1; } else { - if (VIR_STRDUP(path, dev->source.caps.u.misc.chardev) < 0) - return -1; + path =3D g_strdup(dev->source.caps.u.misc.chardev); } ret =3D virSecuritySELinuxSetFilecon(mgr, path, secdef->imagelabel= , true); VIR_FREE(path); @@ -2449,8 +2441,7 @@ virSecuritySELinuxRestoreHostdevCapsLabel(virSecurity= ManagerPtr mgr, dev->source.caps.u.storage.block) < 0) return -1; } else { - if (VIR_STRDUP(path, dev->source.caps.u.storage.block) < 0) - return -1; + path =3D g_strdup(dev->source.caps.u.storage.block); } ret =3D virSecuritySELinuxRestoreFileLabel(mgr, path, true); VIR_FREE(path); @@ -2463,8 +2454,7 @@ virSecuritySELinuxRestoreHostdevCapsLabel(virSecurity= ManagerPtr mgr, dev->source.caps.u.misc.chardev) < 0) return -1; } else { - if (VIR_STRDUP(path, dev->source.caps.u.misc.chardev) < 0) - return -1; + path =3D g_strdup(dev->source.caps.u.misc.chardev); } ret =3D virSecuritySELinuxRestoreFileLabel(mgr, path, true); VIR_FREE(path); @@ -3335,8 +3325,7 @@ virSecuritySELinuxGenImageLabel(virSecurityManagerPtr= mgr, } range =3D context_range_get(ctx); if (range) { - if (VIR_STRDUP(mcs, range) < 0) - goto cleanup; + mcs =3D g_strdup(range); if (!(label =3D virSecuritySELinuxGenNewContext(data->file_con= text, mcs, true))) goto cleanup; diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c index 9157411133..7d7262ca39 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -772,8 +772,7 @@ vah_add_path(virBufferPtr buf, const char *path, const = char *perms, bool recursi * 3. re-combine the realpath with the remaining suffix * Note: A totally non existent path is used as-is */ - if (VIR_STRDUP_QUIET(pathdir, path) < 0) - goto cleanup; + pathdir =3D g_strdup(path); while (!virFileExists(pathdir)) { if ((pathtmp =3D mdir_name(pathdir)) =3D=3D NULL) goto cleanup; @@ -783,11 +782,9 @@ vah_add_path(virBufferPtr buf, const char *path, const= char *perms, bool recursi =20 if (strlen(pathdir) =3D=3D 1) { /* nothing of the path does exist yet */ - if (VIR_STRDUP_QUIET(tmp, path) < 0) - goto cleanup; + tmp =3D g_strdup(path); } else { - if (VIR_STRDUP_QUIET(pathtmp, path+strlen(pathdir)) < 0) - goto cleanup; + pathtmp =3D g_strdup(path + strlen(pathdir)); if ((pathreal =3D realpath(pathdir, NULL)) =3D=3D NULL) { vah_error(NULL, 0, pathdir); vah_error(NULL, 0, _("could not find realpath")); @@ -797,8 +794,7 @@ vah_add_path(virBufferPtr buf, const char *path, const = char *perms, bool recursi goto cleanup; } =20 - if (VIR_STRDUP_QUIET(perms_new, perms) < 0) - goto cleanup; + perms_new =3D g_strdup(perms); =20 if (strchr(perms_new, 'w') !=3D NULL) { readonly =3D false; @@ -1367,8 +1363,7 @@ vahParseArgv(vahControl * ctl, int argc, char **argv) break; case 'f': case 'F': - if (VIR_STRDUP_QUIET(ctl->newfile, optarg) < 0) - vah_error(ctl, 1, _("could not allocate memory for dis= k")); + ctl->newfile =3D g_strdup(optarg); ctl->append =3D arg =3D=3D 'F'; break; case 'h': --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list