From nobody Wed May 15 13:21:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1643395317; cv=none; d=zohomail.com; s=zohoarc; b=nIAQEDIbxnNoyM+s3X2R9TbKXd/2diQaPmEczYUBtW/gH8KBkeh506E0Crpgg1+GboGpaEAg6Hufl6rE8IhIB86Y3YggHGBnBu34+tp94XvL2wrAykG5ot88RSvVq6NnWqyoF8kFjM29S7iKTG2iyE/A6Eat++rAyratySu/wpM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1643395317; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=Z3gsJnFpJ8sUy83vWccLduxEpgkeQaYqMB/NdUQ0TqU=; b=CaJmrj3+nUwSj6v/e9r72SGllcsgeiTceAOILFUFKIlhDkC19J5NvvbwNxPdlPJkOnfGEMJABiDEL6X37hWvWJWeH/WkZQ4vEulQWc169IOsqOkbvG2wEX7jrsxqsGUQfR4Eb8KEIYSDavfdr2crMnhGSX9FRU4wEw36prGDJz4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1643395317369571.2204904263633; Fri, 28 Jan 2022 10:41:57 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-124-Fi990iutPY2X6UdY_l9QyA-1; Fri, 28 Jan 2022 13:41:52 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DE2D08519E0; Fri, 28 Jan 2022 18:41:44 +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 8959210A4B43; Fri, 28 Jan 2022 18:41:42 +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 D50CB1809CB8; Fri, 28 Jan 2022 18:41:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 20SIfarV006228 for ; Fri, 28 Jan 2022 13:41:36 -0500 Received: by smtp.corp.redhat.com (Postfix) id 5A1D810A4B3F; Fri, 28 Jan 2022 18:41:36 +0000 (UTC) Received: from hjs.redhat.com (unknown [10.43.2.85]) by smtp.corp.redhat.com (Postfix) with ESMTP id D7ABE10A4B45 for ; Fri, 28 Jan 2022 18:41:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643395316; 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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Z3gsJnFpJ8sUy83vWccLduxEpgkeQaYqMB/NdUQ0TqU=; b=jPHySBuBqjRrvW8Bw25YljmfwXpP8PsjwMoUM8kIrCBPzbiLp9yEZ75PJbAZ2e+q5WsSEh z4uy74PtbFv7CedkJu29OnHmx6QNU02h422+6/XsfdLN4fzBQVwYTVIR6ZOGa2+qErcetJ O445wxJGDB2XkaHqZwRQ9mYZJP0WO+Q= X-MC-Unique: Fi990iutPY2X6UdY_l9QyA-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCH] tests: refactor testSELinuxLoadDef Date: Fri, 28 Jan 2022 19:41:34 +0100 Message-Id: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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.22 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) X-ZM-MESSAGEID: 1643395319858100001 Since its introduction in commit 907a39e735d256b8428ed4c77009d1f713aea19b Add a test suite for validating SELinux labelling this function did not return NULL on OOM. Since we abort on OOM now, switch testSELinuxMungePath to void, return NULL explicitly on XML parsing failure and remove the (now pointless) cleanup label. Signed-off-by: J=C3=A1n Tomko Reviewed-by: Michal Privoznik --- tests/securityselinuxlabeltest.c | 35 +++++++++++--------------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/tests/securityselinuxlabeltest.c b/tests/securityselinuxlabelt= est.c index 09902e1c54..b62162fe9f 100644 --- a/tests/securityselinuxlabeltest.c +++ b/tests/securityselinuxlabeltest.c @@ -82,16 +82,12 @@ testUserXattrEnabled(void) return ret; } =20 -static int +static void testSELinuxMungePath(char **path) { - char *tmp; - - tmp =3D g_strdup_printf("%s/securityselinuxlabeldata%s", abs_builddir,= *path); - - VIR_FREE(*path); + char *tmp =3D g_strdup_printf("%s/securityselinuxlabeldata%s", abs_bui= lddir, *path); + g_free(*path); *path =3D tmp; - return 0; } =20 static int @@ -154,7 +150,7 @@ testSELinuxLoadFileList(const char *testname, static virDomainDef * testSELinuxLoadDef(const char *testname) { - char *xmlfile =3D NULL; + g_autofree char *xmlfile =3D NULL; virDomainDef *def =3D NULL; size_t i; =20 @@ -163,15 +159,14 @@ testSELinuxLoadDef(const char *testname) =20 if (!(def =3D virDomainDefParseFile(xmlfile, driver.xmlopt, NULL, 0))) - goto cleanup; + return NULL; =20 for (i =3D 0; i < def->ndisks; i++) { if (def->disks[i]->src->type !=3D VIR_STORAGE_TYPE_FILE && def->disks[i]->src->type !=3D VIR_STORAGE_TYPE_BLOCK) continue; =20 - if (testSELinuxMungePath(&def->disks[i]->src->path) < 0) - goto cleanup; + testSELinuxMungePath(&def->disks[i]->src->path); } =20 for (i =3D 0; i < def->nserials; i++) { @@ -182,23 +177,17 @@ testSELinuxLoadDef(const char *testname) continue; =20 if (def->serials[i]->source->type =3D=3D VIR_DOMAIN_CHR_TYPE_UNIX)= { - if (testSELinuxMungePath(&def->serials[i]->source->data.nix.pa= th) < 0) - goto cleanup; + testSELinuxMungePath(&def->serials[i]->source->data.nix.path); } else { - if (testSELinuxMungePath(&def->serials[i]->source->data.file.p= ath) < 0) - goto cleanup; + testSELinuxMungePath(&def->serials[i]->source->data.file.path); } } =20 - if (def->os.kernel && - testSELinuxMungePath(&def->os.kernel) < 0) - goto cleanup; - if (def->os.initrd && - testSELinuxMungePath(&def->os.initrd) < 0) - goto cleanup; + if (def->os.kernel) + testSELinuxMungePath(&def->os.kernel); + if (def->os.initrd) + testSELinuxMungePath(&def->os.initrd); =20 - cleanup: - VIR_FREE(xmlfile); return def; } =20 --=20 2.34.1