From nobody Mon Feb 9 08:31:33 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 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=1565793222; cv=none; d=zoho.com; s=zohoarc; b=EwBkSqQs9uYd/N8T8fRVB3QEjWIzfuRD0kN9hhA5jD05UoK1jwDVTAmFX822BwLVuiMJKcGvXDoMnNtMetbyn5V0oI7wuXsV3pUrPU1skRc9BuKEL0AHndKwHTjj5vVX8LhAdTZl2e2jWxycAsxqMnXm0zyCVgdEYP56/3vH03c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565793222; 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:ARC-Authentication-Results; bh=Mg0s+qz7tnPbiU6t3kLxNBKb/Pm2hkcichHpJoTMEKE=; b=KZCEKp4903pZlIBR2S9UJ1w5Gp1KM+ibpMgC7lQKrtNc8HumSWRx8THa0uMXLYFy0Nen7VDkaYKy3/0IQ43G0OqQIE8ggpU30c0xIrWwUQJSJRIPDicMV+Z14DspA0qWojcpHDsmxt7CQ3FcUUYNLCFbnI13Jl0RLB9OoIybDVo= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1565793222731197.52544895326082; Wed, 14 Aug 2019 07:33:42 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 971FA19CF89; Wed, 14 Aug 2019 14:33:41 +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 735A960D26; Wed, 14 Aug 2019 14:33:41 +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 2928C1806B01; Wed, 14 Aug 2019 14:33:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x7EEXVwF022524 for ; Wed, 14 Aug 2019 10:33:31 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5B45A8309C; Wed, 14 Aug 2019 14:33:31 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id DA5533ACA for ; Wed, 14 Aug 2019 14:33:30 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 14 Aug 2019 16:33:20 +0200 Message-Id: <946248ae4d4d7d87f099007141a935242c7a05a7.1565790969.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/5] security_util: Use more VIR_AUTOFREE() 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: , Content-Transfer-Encoding: quoted-printable 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-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 14 Aug 2019 14:33:42 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Signed-off-by: Michal Privoznik Reviewed-by: Jiri Denemark --- src/security/security_util.c | 78 +++++++++++++++--------------------- 1 file changed, 32 insertions(+), 46 deletions(-) diff --git a/src/security/security_util.c b/src/security/security_util.c index 9d3f483f6b..04347f51e5 100644 --- a/src/security/security_util.c +++ b/src/security/security_util.c @@ -113,34 +113,32 @@ virSecurityGetRememberedLabel(const char *name, const char *path, char **label) { - char *ref_name =3D NULL; - char *attr_name =3D NULL; - char *value =3D NULL; + VIR_AUTOFREE(char *) ref_name =3D NULL; + VIR_AUTOFREE(char *) attr_name =3D NULL; + VIR_AUTOFREE(char *) value =3D NULL; unsigned int refcount =3D 0; - int ret =3D -1; =20 *label =3D NULL; =20 if (!(ref_name =3D virSecurityGetRefCountAttrName(name))) - goto cleanup; + return -1; =20 if (virFileGetXAttrQuiet(path, ref_name, &value) < 0) { - if (errno =3D=3D ENOSYS || errno =3D=3D ENODATA || errno =3D=3D EN= OTSUP) { - ret =3D -2; - } else { - virReportSystemError(errno, - _("Unable to get XATTR %s on %s"), - ref_name, - path); - } - goto cleanup; + if (errno =3D=3D ENOSYS || errno =3D=3D ENODATA || errno =3D=3D EN= OTSUP) + return -2; + + virReportSystemError(errno, + _("Unable to get XATTR %s on %s"), + ref_name, + path); + return -1; } =20 if (virStrToLong_ui(value, NULL, 10, &refcount) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("malformed refcount %s on %s"), value, path); - goto cleanup; + return -1; } =20 VIR_FREE(value); @@ -149,30 +147,25 @@ virSecurityGetRememberedLabel(const char *name, =20 if (refcount > 0) { if (virAsprintf(&value, "%u", refcount) < 0) - goto cleanup; + return -1; =20 if (virFileSetXAttr(path, ref_name, value) < 0) - goto cleanup; + return -1; } else { if (virFileRemoveXAttr(path, ref_name) < 0) - goto cleanup; + return -1; =20 if (!(attr_name =3D virSecurityGetAttrName(name))) - goto cleanup; + return -1; =20 if (virFileGetXAttr(path, attr_name, label) < 0) - goto cleanup; + return -1; =20 if (virFileRemoveXAttr(path, attr_name) < 0) - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - VIR_FREE(value); - VIR_FREE(attr_name); - VIR_FREE(ref_name); - return ret; + return 0; } =20 =20 @@ -201,25 +194,23 @@ virSecuritySetRememberedLabel(const char *name, const char *path, const char *label) { - char *ref_name =3D NULL; - char *attr_name =3D NULL; - char *value =3D NULL; + VIR_AUTOFREE(char *) ref_name =3D NULL; + VIR_AUTOFREE(char *) attr_name =3D NULL; + VIR_AUTOFREE(char *) value =3D NULL; unsigned int refcount =3D 0; - int ret =3D -1; =20 if (!(ref_name =3D virSecurityGetRefCountAttrName(name))) - goto cleanup; + return -1; =20 if (virFileGetXAttrQuiet(path, ref_name, &value) < 0) { if (errno =3D=3D ENOSYS || errno =3D=3D ENOTSUP) { - ret =3D -2; - goto cleanup; + return -2; } else if (errno !=3D ENODATA) { virReportSystemError(errno, _("Unable to get XATTR %s on %s"), ref_name, path); - goto cleanup; + return -1; } } =20 @@ -228,7 +219,7 @@ virSecuritySetRememberedLabel(const char *name, virReportError(VIR_ERR_INTERNAL_ERROR, _("malformed refcount %s on %s"), value, path); - goto cleanup; + return -1; } =20 VIR_FREE(value); @@ -237,24 +228,19 @@ virSecuritySetRememberedLabel(const char *name, =20 if (refcount =3D=3D 1) { if (!(attr_name =3D virSecurityGetAttrName(name))) - goto cleanup; + return -1; =20 if (virFileSetXAttr(path, attr_name, label) < 0) - goto cleanup; + return -1; } =20 if (virAsprintf(&value, "%u", refcount) < 0) - goto cleanup; + return -1; =20 if (virFileSetXAttr(path, ref_name, value) < 0) - goto cleanup; + return -1; =20 - ret =3D refcount; - cleanup: - VIR_FREE(value); - VIR_FREE(attr_name); - VIR_FREE(ref_name); - return ret; + return refcount; } =20 =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list