libsepol: do not dereference scope if it can be NULL

Doing this looks wrong:

    len = scope->decl_ids_len;
    if (scope == NULL) {
        /* ... */

Move the dereferencing of scope after the NULL check.

This issue has been found using Infer static analyzer.

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

View File

@ -157,7 +157,7 @@ int is_id_enabled(char *id, policydb_t * p, int symbol_table)
scope_datum_t *scope =
(scope_datum_t *) hashtab_search(p->scope[symbol_table].table, id);
avrule_decl_t *decl;
uint32_t len = scope->decl_ids_len;
uint32_t len;
if (scope == NULL) {
return 0;
@ -166,6 +166,7 @@ int is_id_enabled(char *id, policydb_t * p, int symbol_table)
return 0;
}
len = scope->decl_ids_len;
if (len < 1) {
return 0;
}