Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntax error causes panic #916

Closed
dan6518 opened this issue Aug 30, 2018 · 1 comment
Closed

Syntax error causes panic #916

dan6518 opened this issue Aug 30, 2018 · 1 comment
Labels

Comments

@dan6518
Copy link

dan6518 commented Aug 30, 2018

I tried to use the result of a function as the input to a test, and caused the syntax parser to panic. Here's a minimal reproduction:

rule {
    input.asdf = 2
}

f(x) = y {
    y = {
        "asdf": x * 2
    }
}

#test_1 {
#    rule with input as f(1)
#}

test_2 {
    y = f(1)
    rule with input as y
}

Test number 1 causes the following panic:

panic: unreachable [recovered]
        panic: unreachable

goroutine 1 [running]:
github.com/open-policy-agent/opa/ast.(*Compiler).compile.func1()
        /go/src/github.com/open-policy-agent/opa/ast/compile.go:605 +0x71
panic(0x9b0460, 0xb18c30)
        /usr/local/go/src/runtime/panic.go:502 +0x237
github.com/open-policy-agent/opa/ast.(*TypeEnv).Get(0xc0425104c0, 0xa56080, 0xc0422d9040, 0x0, 0x0)
        /go/src/github.com/open-policy-agent/opa/ast/env.go:133 +0x1058
github.com/open-policy-agent/opa/ast.(*typeChecker).checkExprEq(0xc0421315a0, 0xc0425104c0, 0xc0422a30e0, 0xc042478320)
        /go/src/github.com/open-policy-agent/opa/ast/check.go:261 +0xfc
github.com/open-policy-agent/opa/ast.(*typeChecker).(github.com/open-policy-agent/opa/ast.checkExprEq)-fm(0xc0425104c0, 0xc0422a30e0, 0xaa654e)
        /go/src/github.com/open-policy-agent/opa/ast/check.go:33 +0x45
github.com/open-policy-agent/opa/ast.(*typeChecker).checkExpr(0xc0421315a0, 0xc0425104c0, 0xc0422a30e0, 0xc0422a30e0)
        /go/src/github.com/open-policy-agent/opa/ast/check.go:205 +0xcd
github.com/open-policy-agent/opa/ast.(*typeChecker).CheckBody.func1(0xc0422a30e0, 0x542ba12425103d0)
        /go/src/github.com/open-policy-agent/opa/ast/check.go:66 +0x303
github.com/open-policy-agent/opa/ast.WalkExprs.func1(0xa7f100, 0xc0422a30e0, 0xc0425103d0)
        /go/src/github.com/open-policy-agent/opa/ast/visit.go:199 +0x49
github.com/open-policy-agent/opa/ast.(*GenericVisitor).Visit(0xc0421600b8, 0xa7f100, 0xc0422a30e0, 0x18, 0xc0436433d0)
        /go/src/github.com/open-policy-agent/opa/ast/visit.go:245 +0x44
github.com/open-policy-agent/opa/ast.WalkBeforeAndAfter(0xb21520, 0xc0425104f0, 0xa7f100, 0xc0422a30e0)
        /go/src/github.com/open-policy-agent/opa/ast/visit.go:38 +0xed
github.com/open-policy-agent/opa/ast.Walk(0xb1b940, 0xc0421600b8, 0xa7f100, 0xc0422a30e0)
        /go/src/github.com/open-policy-agent/opa/ast/visit.go:30 +0x81
github.com/open-policy-agent/opa/ast.WalkBeforeAndAfter(0xb21520, 0xc0425104e0, 0xa5b600, 0xc0424da5e0)
        /go/src/github.com/open-policy-agent/opa/ast/visit.go:76 +0xb84
github.com/open-policy-agent/opa/ast.Walk(0xb1b940, 0xc0421600b8, 0xa5b600, 0xc0424da5e0)
        /go/src/github.com/open-policy-agent/opa/ast/visit.go:30 +0x81
github.com/open-policy-agent/opa/ast.WalkExprs(0xa5b600, 0xc0424da5e0, 0xc0424da5c0)
        /go/src/github.com/open-policy-agent/opa/ast/visit.go:203 +0xa9
github.com/open-policy-agent/opa/ast.(*typeChecker).CheckBody(0xc0421315a0, 0xc0425104c0, 0xc0424cfab0, 0x2, 0x2, 0xc042394b70, 0x0, 0x0, 0x0)
        /go/src/github.com/open-policy-agent/opa/ast/check.go:49 +0x1db
github.com/open-policy-agent/opa/ast.(*typeChecker).checkRule(0xc0421315a0, 0xc042372160, 0xc0424f6700)
        /go/src/github.com/open-policy-agent/opa/ast/check.go:136 +0x7a
github.com/open-policy-agent/opa/ast.(*typeChecker).CheckTypes(0xc0421315a0, 0xc042372160, 0xc0420ba2c0, 0xb, 0xb, 0x0, 0x0, 0x6000103, 0x0)
        /go/src/github.com/open-policy-agent/opa/ast/check.go:93 +0x14b
github.com/open-policy-agent/opa/ast.(*Compiler).checkTypes(0xc042159340)
        /go/src/github.com/open-policy-agent/opa/ast/compile.go:595 +0xa2
github.com/open-policy-agent/opa/ast.(*Compiler).(github.com/open-policy-agent/opa/ast.checkTypes)-fm()
        /go/src/github.com/open-policy-agent/opa/ast/compile.go:218 +0x31
github.com/open-policy-agent/opa/ast.(*Compiler).compile(0xc042159340)
        /go/src/github.com/open-policy-agent/opa/ast/compile.go:610 +0x88
github.com/open-policy-agent/opa/ast.(*Compiler).Compile(0xc042159340, 0xc0424fbc80)
        /go/src/github.com/open-policy-agent/opa/ast/compile.go:246 +0x190
github.com/open-policy-agent/opa/tester.(*Runner).Run(0xc0424fbcb0, 0xb21d20, 0xc04216c300, 0xc0424fbc80, 0xc0424fbc80, 0xb263c0, 0xc0424a60a0)
        /go/src/github.com/open-policy-agent/opa/tester/runner.go:139 +0x236
github.com/open-policy-agent/opa/cmd.opaTest(0xc042188440, 0x1, 0x2, 0x0)
        /go/src/github.com/open-policy-agent/opa/cmd/test.go:123 +0x28c
github.com/open-policy-agent/opa/cmd.glob..func7(0xe354c0, 0xc042188440, 0x1, 0x2)
        /go/src/github.com/open-policy-agent/opa/cmd/test.go:91 +0x46
github.com/open-policy-agent/opa/vendor/github.com/spf13/cobra.(*Command).execute(0xe354c0, 0xc042188420, 0x2, 0x2, 0xe354c0, 0xc042188420)
        /go/src/github.com/open-policy-agent/opa/vendor/github.com/spf13/cobra/command.go:651 +0x244
github.com/open-policy-agent/opa/vendor/github.com/spf13/cobra.(*Command).ExecuteC(0xe34e60, 0xc0421b5f68, 0x945f9c, 0xc0421b5f78)
        /go/src/github.com/open-policy-agent/opa/vendor/github.com/spf13/cobra/command.go:726 +0x2db
github.com/open-policy-agent/opa/vendor/github.com/spf13/cobra.(*Command).Execute(0xe34e60, 0x2, 0xc04215df20)
        /go/src/github.com/open-policy-agent/opa/vendor/github.com/spf13/cobra/command.go:685 +0x32
main.main()
        /go/src/github.com/open-policy-agent/opa/main.go:12 +0x34

Test 2 shows the correct way to do what I was trying to do for anyone else who comes across this problem.

@tsandall tsandall added the bug label Aug 30, 2018
@tsandall
Copy link
Member

Thanks for reporting this @dan6518!

This might be related to #772 though I need to look into it more closely.

Expect a fix shortly.

tsandall added a commit to tsandall/opa that referenced this issue Aug 31, 2018
If a call term was used as a with value, e.g., "p with input as f(1)"
the type checker would panic because the call was not expanded as
expected. These changes update the rewrite term expr stage to rewrite
with values like other AST nodes such as calls and composites.

Also, add an extra test case for with value rewriting to cover open-policy-agent#772.

Fixes open-policy-agent#916

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
tsandall added a commit that referenced this issue Aug 31, 2018
If a call term was used as a with value, e.g., "p with input as f(1)"
the type checker would panic because the call was not expanded as
expected. These changes update the rewrite term expr stage to rewrite
with values like other AST nodes such as calls and composites.

Also, add an extra test case for with value rewriting to cover #772.

Fixes #916

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants