]> git.itanic.dy.fi Git - linux-stable/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)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 24 Jun 2020 15:49:19 +0000 (17:49 +0200)
commit145fa7a97a5013f10a10e702d63a9ba5bfd75813
tree87f1b62aa8f419cc4bb4bd7deeda9045e3f9dff7
parent5b566a7959adc7e07e11df57c3f776e5c177280c
selinux: fix undefined return of cond_evaluate_expr

commit 8231b0b9c322c894594fb42eb0eb9f93544a6acc upstream.

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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
security/selinux/ss/conditional.c