diff --git a/libsepol/src/context.c b/libsepol/src/context.c index 84dad348..420ee16b 100644 --- a/libsepol/src/context.c +++ b/libsepol/src/context.c @@ -55,7 +55,7 @@ int context_is_valid(const policydb_t * p, const context_struct_t * c) * Role must be authorized for the type. */ role = p->role_val_to_struct[c->role - 1]; - if (!ebitmap_get_bit(&role->cache, c->type - 1)) + if (!role || !ebitmap_get_bit(&role->cache, c->type - 1)) /* role may not be associated with type */ return 0; diff --git a/libsepol/src/policydb.c b/libsepol/src/policydb.c index b8f6ca8f..60761b7f 100644 --- a/libsepol/src/policydb.c +++ b/libsepol/src/policydb.c @@ -1068,7 +1068,7 @@ int policydb_index_others(sepol_handle_t * handle, free(p->role_val_to_struct); p->role_val_to_struct = (role_datum_t **) - malloc(p->p_roles.nprim * sizeof(role_datum_t *)); + calloc(p->p_roles.nprim, sizeof(role_datum_t *)); if (!p->role_val_to_struct) return -1;