[PATCH] invalid memory allocation in policydb_index_others()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



There is an error in libsepol's policydb_index_others().  If a policy
is lacking symbols of some kind (e.g., a policy with no booleans),
then the function will attempt a calloc() of 0, which is undefined.
The following patch checks for this condition and explicitly sets the
field upon zero symbols.

Index: libsepol/src/policydb.c
===================================================================
--- libsepol/src/policydb.c	(revision 2804)
+++ libsepol/src/policydb.c	(working copy)
@@ -820,14 +820,16 @@
 	cond_init_bool_indexes(p);
 
 	for (i = SYM_ROLES; i < SYM_NUM; i++) {
-		if (p->sym_val_to_name[i])
-			free(p->sym_val_to_name[i]);
-		p->sym_val_to_name[i] = (char **)
-		    calloc(p->symtab[i].nprim, sizeof(char *));
-		if (!p->sym_val_to_name[i])
-			return -1;
-		if (hashtab_map(p->symtab[i].table, index_f[i], p))
-			return -1;
+		free(p->sym_val_to_name[i]);
+		p->sym_val_to_name[i] = NULL;
+		if (p->symtab[i].nprim) {
+			p->sym_val_to_name[i] = (char **)
+			    calloc(p->symtab[i].nprim, sizeof(char *));
+			if (!p->sym_val_to_name[i])
+				return -1;
+			if (hashtab_map(p->symtab[i].table, index_f[i], p))
+				return -1;
+		}
 	}
 
 	/* This pre-expands the roles and users for context validity checking */


-- 
Jason Tang / jtang@xxxxxxxxxx

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

[Index of Archives]     [Selinux Refpolicy]     [Linux SGX]     [Fedora Users]     [Fedora Desktop]     [Yosemite Photos]     [Yosemite Camping]     [Yosemite Campsites]     [KDE Users]     [Gnome Users]

  Powered by Linux