]> Git Repo - linux.git/commitdiff
selinux: fix undefined return of cond_evaluate_expr
authorTom Rix <[email protected]>
Wed, 17 Jun 2020 12:40:28 +0000 (05:40 -0700)
committerPaul Moore <[email protected]>
Wed, 17 Jun 2020 21:36:40 +0000 (17:36 -0400)
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: [email protected]
Signed-off-by: Tom Rix <[email protected]>
Acked-by: Stephen Smalley <[email protected]>
Signed-off-by: Paul Moore <[email protected]>
security/selinux/ss/conditional.c

index 4867dfc5337ac17ee7e803918d7c20b382f6fb56..7a92b028f7223c39d880e247629d2d88d9ede04f 100644 (file)
@@ -27,6 +27,9 @@ static int cond_evaluate_expr(struct policydb *p, struct cond_expr *expr)
        int s[COND_EXPR_MAXDEPTH];
        int sp = -1;
 
+       if (expr->len == 0)
+               return -1;
+
        for (i = 0; i < expr->len; i++) {
                struct cond_expr_node *node = &expr->nodes[i];
 
This page took 0.050203 seconds and 4 git commands to generate.