libsepol/tests: do not dereference a NULL pointer

In test_attr_types, the pointer decl is allowed to be NULL in the
beginning, but is dereferenced to produce a helpful message right before
a CU_ASSERT_FATAL. Make this derefence not happen if the pointer is
NULL.

This issue has been found using clang's static analyzer.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
This commit is contained in:
Nicolas Iooss 2019-09-01 20:06:36 +02:00 committed by James Carter
parent 0da7718310
commit cfc57c2e70

View file

@ -228,13 +228,16 @@ void test_attr_types(policydb_t * p, const char *id, avrule_decl_t * decl, const
unsigned int i;
type_datum_t *attr;
if (decl)
if (decl) {
attr = hashtab_search(decl->p_types.table, id);
else
attr = hashtab_search(p->p_types.table, id);
if (attr == NULL)
printf("could not find attr %s in decl %d\n", id, decl->decl_id);
} else {
attr = hashtab_search(p->p_types.table, id);
if (attr == NULL)
printf("could not find attr %s in policy\n", id);
}
CU_ASSERT_FATAL(attr != NULL);
CU_ASSERT(attr->flavor == TYPE_ATTRIB);
CU_ASSERT(attr->primary == 1);