selinux: fix return value on error in policydb_read()
authorOndrej Mosnacek <omosnace@redhat.com>
Fri, 1 May 2020 19:51:11 +0000 (21:51 +0200)
committerPaul Moore <paul@paul-moore.com>
Fri, 1 May 2020 20:08:46 +0000 (16:08 -0400)
The value of rc is still zero from the last assignment when the error
path is taken. Fix it by setting it to -ENOMEM before the
hashtab_create() call.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Fixes: e67b2ec9f617 ("selinux: store role transitions in a hash table")
Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>
security/selinux/ss/policydb.c

index 8a287a7..76358c9 100644 (file)
@@ -2540,6 +2540,7 @@ int policydb_read(struct policydb *p, void *fp)
                goto bad;
        nel = le32_to_cpu(buf[0]);
 
+       rc = -ENOMEM;
        p->role_tr = hashtab_create(role_trans_hash, role_trans_cmp, nel);
        if (!p->role_tr)
                goto bad;