libsepol: do not dereference a failed allocated pointer
When strs_stack_init(&stack) fails to allocate memory and stack is still NULL, it should not be dereferenced with strs_stack_pop(stack). This issue has been found using Infer static analyzer. Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
This commit is contained in:
parent
4459d635b8
commit
4a266cc3ce
2 changed files with 20 additions and 12 deletions
|
@ -108,10 +108,12 @@ static char *cond_expr_to_str(struct policydb *pdb, struct cond_expr *expr)
|
|||
return str;
|
||||
|
||||
exit:
|
||||
if (stack) {
|
||||
while ((new_val = strs_stack_pop(stack)) != NULL) {
|
||||
free(new_val);
|
||||
}
|
||||
strs_stack_destroy(&stack);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
@ -251,10 +253,12 @@ static char *constraint_expr_to_str(struct policydb *pdb, struct constraint_expr
|
|||
return str;
|
||||
|
||||
exit:
|
||||
if (stack) {
|
||||
while ((new_val = strs_stack_pop(stack)) != NULL) {
|
||||
free(new_val);
|
||||
}
|
||||
strs_stack_destroy(&stack);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -106,10 +106,12 @@ static char *cond_expr_to_str(struct policydb *pdb, struct cond_expr *expr)
|
|||
return str;
|
||||
|
||||
exit:
|
||||
if (stack) {
|
||||
while ((new_val = strs_stack_pop(stack)) != NULL) {
|
||||
free(new_val);
|
||||
}
|
||||
strs_stack_destroy(&stack);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
@ -247,10 +249,12 @@ static char *constraint_expr_to_str(struct policydb *pdb, struct constraint_expr
|
|||
return str;
|
||||
|
||||
exit:
|
||||
if (stack) {
|
||||
while ((new_val = strs_stack_pop(stack)) != NULL) {
|
||||
free(new_val);
|
||||
}
|
||||
strs_stack_destroy(&stack);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue