checkpolicy/dismod: avoid duplicate initialization and fix module linking

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>
Acked-by: James Carter <jwcart2@gmail.com>
This commit is contained in:
Christian Göttsche 2023-11-28 19:23:30 +01:00 committed by James Carter
parent 4f1435dd51
commit 58a444fb84
1 changed files with 6 additions and 4 deletions

View File

@ -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",