Skip to contentSkip to conversation

fix decl val index, other leaks

PATCH Joshua Brindle 1 participant 1 message Jun 23, 2006 SELinux security module

lore
Share & tools
lore
#0 lore raw

This makes the decl_val_to_struct index have a -1 offset to be consistent with all the other indexes. It also fixes some memory leaks in checkmodule and a fd leak in semodule_link.

checkpolicy/checkmodule.c +5 -0
diff -purN -x.svn trunk/checkpolicy/checkmodule.c optionals-in-base-take2/checkpolicy/checkmodule.c
@@ -27,6 +27,7 @@
 #include <sepol/policydb/hierarchy.h>
 #include <sepol/policydb/expand.h>
 #include <sepol/policydb/link.h>
+#include <sepol/policydb/sidtab.h>
 
 #include "queue.h"
 #include "checkpolicy.h"
@@ -244,12 +245,16 @@ int main(int argc, char **argv)
 	if (policydb_load_isids(&modpolicydb, &sidtab))
 		exit(1);
 
+	sepol_sidtab_destroy(&sidtab);
+
 	printf("%s:  policy configuration loaded\n", argv[0]);
 
 	if (outfile &&
             write_binary_policy(&modpolicydb, outfile, argv[0]) == -1) {
                 exit(1);
         }
+	policydb_destroy(&modpolicydb);
+
 	return 0;
 }
 
libsepol/src/avrule_block.c +1 -1
diff -purN -x.svn trunk/libsepol/src/avrule_block.c optionals-in-base-take2/libsepol/src/avrule_block.c
@@ -155,7 +155,7 @@ int is_id_enabled(char *id, policydb_t *
                 return 0;
         }
         for (i = 0; i < scope->decl_ids_len; i++) {
-                avrule_decl_t *decl = p->decl_val_to_struct[scope->decl_ids[i]];
+                avrule_decl_t *decl = p->decl_val_to_struct[scope->decl_ids[i] - 1];
                 if (decl != NULL && decl->enabled) {
                         return 1;
                 }
libsepol/src/link.c +2 -2
diff -purN -x.svn trunk/libsepol/src/link.c optionals-in-base-take2/libsepol/src/link.c
@@ -1239,7 +1239,7 @@ static int copy_avrule_block(link_state_
                         last_decl->next = new_decl;
                 }
                 last_decl = new_decl;
-                state->base->decl_val_to_struct[state->next_decl_id] = new_decl;
+                state->base->decl_val_to_struct[state->next_decl_id - 1] = new_decl;
 		state->decl_to_mod[state->next_decl_id] = module->policy;
                 module->avdecl_map[decl->decl_id] = new_decl->decl_id;
 
@@ -1788,7 +1788,7 @@ static int prepare_base(link_state_t *st
         while (cur != NULL) {
                 avrule_decl_t *decl = cur->branch_list;
                 while (decl != NULL) {
-                        state->base->decl_val_to_struct[decl->decl_id] = decl;
+                        state->base->decl_val_to_struct[decl->decl_id - 1] = decl;
 			state->decl_to_mod[decl->decl_id] = state->base;
                         decl = decl->next;
                 }
libsepol/src/policydb.c +2 -2
diff -purN -x.svn trunk/libsepol/src/policydb.c optionals-in-base-take2/libsepol/src/policydb.c
@@ -655,7 +655,7 @@ int policydb_index_decls(policydb_t *p)
 {
 	avrule_block_t *curblock;
 	avrule_decl_t *decl;
-	int num_decls = 1;
+	int num_decls = 0;
 
 	free(p->decl_val_to_struct);
 
@@ -672,7 +672,7 @@ int policydb_index_decls(policydb_t *p)
 	
 	for (curblock = p->global; curblock != NULL; curblock = curblock->next) {
 		for (decl = curblock->branch_list; decl != NULL; decl = decl->next) {
-			p->decl_val_to_struct[decl->decl_id] = decl;
+			p->decl_val_to_struct[decl->decl_id - 1] = decl;
 		}
 	}
 
policycoreutils/semodule_link/semodule_link.c +2 -0
diff -purN -x.svn trunk/policycoreutils/semodule_link/semodule_link.c optionals-in-base-take2/policycoreutils/semodule_link/semodule_link.c
@@ -153,11 +153,13 @@ int main(int argc, char **argv)
         		exit(1);	
         	}
 		sepol_policy_file_free(pf);
+		fclose(outfile);
         }
 
 	sepol_module_package_free(base);
         for (i = 0; i < num_mods; i++)
         	sepol_module_package_free(mods[i]);
+	free(mods);
 	exit(0);
 }
 

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.