Skip to content

Commit

Permalink
checkpolicy/dismod: avoid duplicate initialization and fix module lin…
Browse files Browse the repository at this point in the history
…king

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 <[email protected]>
Acked-by: James Carter <[email protected]>
  • Loading branch information
cgzones authored and jwcart2 committed Dec 6, 2023
1 parent 4f1435d commit 58a444f
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions checkpolicy/test/dismod.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 58a444f

Please sign in to comment.