libsepol: calloc all the *_to_val_structs

The usage patterns between these structures seem similair
to role_val_to_struct usages. Calloc these up to prevent
any unitialized usages.

Signed-off-by: William Roberts <william.c.roberts@intel.com>
This commit is contained in:
William Roberts 2016-08-19 08:51:27 -07:00 committed by James Carter
parent a1d76acf04
commit fb0cc0cc64
3 changed files with 12 additions and 5 deletions

View File

@ -312,7 +312,7 @@ int mls_context_isvalid(const policydb_t * p, const context_struct_t * c)
if (!c->user || c->user > p->p_users.nprim)
return 0;
usrdatum = p->user_val_to_struct[c->user - 1];
if (!mls_range_contains(usrdatum->exp_range, c->range))
if (!usrdatum || !mls_range_contains(usrdatum->exp_range, c->range))
return 0; /* user may not be associated with range */
return 1;

View File

@ -1074,7 +1074,7 @@ int policydb_index_others(sepol_handle_t * handle,
free(p->user_val_to_struct);
p->user_val_to_struct = (user_datum_t **)
malloc(p->p_users.nprim * sizeof(user_datum_t *));
calloc(p->p_users.nprim, sizeof(user_datum_t *));
if (!p->user_val_to_struct)
return -1;
@ -4006,12 +4006,12 @@ int policydb_reindex_users(policydb_t * p)
free(p->sym_val_to_name[i]);
p->user_val_to_struct = (user_datum_t **)
malloc(p->p_users.nprim * sizeof(user_datum_t *));
calloc(p->p_users.nprim, sizeof(user_datum_t *));
if (!p->user_val_to_struct)
return -1;
p->sym_val_to_name[i] = (char **)
malloc(p->symtab[i].nprim * sizeof(char *));
calloc(p->symtab[i].nprim, sizeof(char *));
if (!p->sym_val_to_name[i])
return -1;

View File

@ -19,12 +19,17 @@ static int user_to_record(sepol_handle_t * handle,
const char *name = policydb->p_user_val_to_name[user_idx];
user_datum_t *usrdatum = policydb->user_val_to_struct[user_idx];
ebitmap_t *roles = &(usrdatum->roles.roles);
ebitmap_t *roles;
ebitmap_node_t *rnode;
unsigned bit;
sepol_user_t *tmp_record = NULL;
if (!usrdatum)
goto err;
roles = &(usrdatum->roles.roles);
if (sepol_user_create(handle, &tmp_record) < 0)
goto err;
@ -234,6 +239,7 @@ int sepol_user_modify(sepol_handle_t * handle,
if (!tmp_ptr)
goto omem;
policydb->user_val_to_struct = tmp_ptr;
policydb->user_val_to_struct[policydb->p_users.nprim] = NULL;
tmp_ptr = realloc(policydb->sym_val_to_name[SYM_USERS],
(policydb->p_users.nprim +
@ -241,6 +247,7 @@ int sepol_user_modify(sepol_handle_t * handle,
if (!tmp_ptr)
goto omem;
policydb->sym_val_to_name[SYM_USERS] = tmp_ptr;
policydb->p_user_val_to_name[policydb->p_users.nprim] = NULL;
/* Need to copy the user name */
name = strdup(cname);