checkpolicy: avoid passing NULL pointer to memset()

Function `class_perm_node_init()` is called with `dest_perms` before it
is checked that its allocation succeeded. If the allocation fails, then
a NULL pointer is passed to `memset()` inside the
`class_perm_node_init()` function.

Signed-off-by: Juraj Marcin <juraj@jurajmarcin.com>
This commit is contained in:
Juraj Marcin 2022-08-29 14:28:40 +02:00 committed by James Carter
parent eca72d8e47
commit c916f0884b
1 changed files with 2 additions and 1 deletions

View File

@ -2371,11 +2371,12 @@ static int avrule_cpy(avrule_t *dest, const avrule_t *src)
src_perms = src->perms;
while (src_perms) {
dest_perms = (class_perm_node_t *) calloc(1, sizeof(class_perm_node_t));
class_perm_node_init(dest_perms);
if (!dest_perms) {
yyerror("out of memory");
return -1;
}
class_perm_node_init(dest_perms);
if (!dest->perms)
dest->perms = dest_perms;
else