diff mbox series

[3/7] checkpolicy/dismod: avoid duplicate initialization and fix module linking

Message ID 20231128182334.57740-3-cgzones@googlemail.com (mailing list archive)
State Accepted
Commit 58a444fb84df
Delegated to: Petr Lautrbach
Headers show
Series [1/7] libsepol: validate conditional type rules have a simple default type | expand

Commit Message

Christian Göttsche Nov. 28, 2023, 6:23 p.m. UTC
Avoid duplicate policydb initialization when reading a kernel policy.
One caller, main(), already performs the initialization.  The other one,
link_module(), needs to do it also for the module policy case.

Also set the target platform to enable module linking.

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
---
 checkpolicy/test/dismod.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/checkpolicy/test/dismod.c b/checkpolicy/test/dismod.c
index 9f4a669b..ac2d61d2 100644
--- a/checkpolicy/test/dismod.c
+++ b/checkpolicy/test/dismod.c
@@ -824,10 +824,6 @@  static int read_policy(char *filename, policydb_t * policy, int verbose)
 		package->policy = NULL;
 		sepol_module_package_free(package);
 	} else {
-		if (policydb_init(policy)) {
-			fprintf(stderr, "%s:  Out of memory!\n", __FUNCTION__);
-			exit(1);
-		}
 		retval = policydb_read(policy, &f, verbose);
 	}
 	fclose(in_fp);
@@ -856,9 +852,15 @@  static void link_module(policydb_t * base, FILE * out_fp, int verbose)
 		return;
 	}
 
+	if (policydb_init(mods)) {
+		fprintf(stderr, "Out of memory!\n");
+		exit(1);
+	}
+
 	/* read the binary policy */
 	if (verbose)
 		fprintf(out_fp, "Reading module...\n");
+	policydb_set_target_platform(mods, base->target_platform);
 	if (read_policy(module_name, mods, verbose)) {
 		fprintf(stderr,
 			"%s:  error(s) encountered while loading policy\n",