]> git.baikalelectronics.ru Git - kernel.git/commit
selinux: fix undefined return of cond_evaluate_expr
authorTom Rix <trix@redhat.com>
Wed, 17 Jun 2020 12:40:28 +0000 (05:40 -0700)
committerPaul Moore <paul@paul-moore.com>
Wed, 17 Jun 2020 21:36:40 +0000 (17:36 -0400)
commit145a09da5e1e0d4938271763813d5c523dae740f
tree69b85357797d0afd34707c655783a036cae386ec
parentdddea2a2bb13edc506028e6b8d589aa3f7e9b3dc
selinux: fix undefined return of cond_evaluate_expr

clang static analysis reports an undefined return

security/selinux/ss/conditional.c:79:2: warning: Undefined or garbage value returned to caller [core.uninitialized.UndefReturn]
        return s[0];
        ^~~~~~~~~~~

static int cond_evaluate_expr( ...
{
u32 i;
int s[COND_EXPR_MAXDEPTH];

for (i = 0; i < expr->len; i++)
  ...

return s[0];

When expr->len is 0, the loop which sets s[0] never runs.

So return -1 if the loop never runs.

Cc: stable@vger.kernel.org
Signed-off-by: Tom Rix <trix@redhat.com>
Acked-by: Stephen Smalley <stephen.smalley.work@gmail.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>
security/selinux/ss/conditional.c