diff mbox

[2/5] libsepol: ensure key is valid before doing search

Message ID 1470865882-22435-2-git-send-email-william.c.roberts@intel.com (mailing list archive)
State Not Applicable
Headers show

Commit Message

Roberts, William C Aug. 10, 2016, 9:51 p.m. UTC
From: William Roberts <william.c.roberts@intel.com>

Signed-off-by: William Roberts <william.c.roberts@intel.com>
---
 libsepol/src/mls.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
diff mbox

Patch

diff --git a/libsepol/src/mls.c b/libsepol/src/mls.c
index 1e84bb7..2dc5f2b 100644
--- a/libsepol/src/mls.c
+++ b/libsepol/src/mls.c
@@ -262,6 +262,7 @@  int mls_context_isvalid(const policydb_t * p, const context_struct_t * c)
 	user_datum_t *usrdatum;
 	unsigned int i, l;
 	ebitmap_node_t *cnode;
+	hashtab_key_t key;
 
 	if (!p->mls)
 		return 1;
@@ -279,11 +280,12 @@  int mls_context_isvalid(const policydb_t * p, const context_struct_t * c)
 		if (!c->range.level[l].sens
 		    || c->range.level[l].sens > p->p_levels.nprim)
 			return 0;
-		levdatum = (level_datum_t *) hashtab_search(p->p_levels.table,
-							    p->
-							    p_sens_val_to_name
-							    [c->range.level[l].
-							     sens - 1]);
+
+		key = p->p_sens_val_to_name[c->range.level[l].sens - 1];
+		if (!key)
+			return 0;
+
+		levdatum = (level_datum_t *) hashtab_search(p->p_levels.table, key);
 		if (!levdatum)
 			return 0;