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

panic during compile if else body missing #2353

Closed
tsandall opened this issue Apr 28, 2020 · 0 comments · Fixed by #2356
Closed

panic during compile if else body missing #2353

tsandall opened this issue Apr 28, 2020 · 0 comments · Fixed by #2356
Assignees
Labels

Comments

@tsandall
Copy link
Member

The compiler panics during one of the rewriting stages because it seems like the parser is emiting rules with an empty body:

$ docker run -it --rm  openpolicyagent/opa:0.19.2
OPA 0.19.2 (commit 40f9c1f, built at 2020-04-27T22:50:42Z)

Run 'help' to see a list of commands.

> p { true } else = false
panic: runtime error: index out of range [0] with length 0 [recovered]
	panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
github.com/open-policy-agent/opa/ast.(*Compiler).compile.func1()
	/src/ast/compile.go:846 +0x73
panic(0xf662e0, 0xc000144ac0)
	/usr/local/go/src/runtime/panic.go:679 +0x1b2
github.com/open-policy-agent/opa/ast.rewriteDeclaredVarsInBody(0xc000204d60, 0xc000204f80, 0xc0002034d0, 0x160aa90, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc00020e901, ...)
	/src/ast/compile.go:3021 +0x5e1
github.com/open-policy-agent/opa/ast.rewriteLocalVars(0xc000204d60, 0xc000204f80, 0xc0002034d0, 0x160aa90, 0x0, 0x0, 0xb9563b, 0xf6c800, 0xf2a2c0, 0x15abb01, ...)
	/src/ast/compile.go:2992 +0x84
github.com/open-policy-agent/opa/ast.(*Compiler).rewriteLocalVars.func1(0xc000147400, 0x203000)
	/src/ast/compile.go:1098 +0x470
github.com/open-policy-agent/opa/ast.WalkRules.func1(0xf576a0, 0xc000147400, 0xc00014c730)
	/src/ast/visit.go:229 +0x56
github.com/open-policy-agent/opa/ast.(*GenericVisitor).Walk(0xc00020eff8, 0xf576a0, 0xc000147400)
	/src/ast/visit.go:270 +0x5b
github.com/open-policy-agent/opa/ast.(*GenericVisitor).Walk(0xc00020eff8, 0xf576a0, 0xc0001473c0)
	/src/ast/visit.go:295 +0xeb0
github.com/open-policy-agent/opa/ast.(*GenericVisitor).Walk(0xc00020eff8, 0xf30a20, 0xc00014c5f0)
	/src/ast/visit.go:281 +0x77a
github.com/open-policy-agent/opa/ast.WalkRules(0xf30a20, 0xc00014c5f0, 0xc0000b5060)
	/src/ast/visit.go:238 +0x70
github.com/open-policy-agent/opa/ast.(*Compiler).rewriteLocalVars(0xc0001ec340)
	/src/ast/compile.go:1043 +0xe2
github.com/open-policy-agent/opa/ast.(*Compiler).runStage(0xc0001ec340, 0xfdf06e, 0x20, 0xc0002064d0)
	/src/ast/compile.go:832 +0x46
github.com/open-policy-agent/opa/ast.(*Compiler).compile(0xc0001ec340)
	/src/ast/compile.go:851 +0x125
github.com/open-policy-agent/opa/ast.(*Compiler).Compile(0xc0001ec340, 0xc0001e7860)
	/src/ast/compile.go:345 +0x2a3
github.com/open-policy-agent/opa/repl.(*REPL).compileRule(0xc0001a6d80, 0x10e8600, 0xc000026050, 0xc000147080, 0x0, 0x0)
	/src/repl/repl.go:704 +0x3a1
github.com/open-policy-agent/opa/repl.(*REPL).evalStatement(0xc0001a6d80, 0x10e8600, 0xc000026050, 0xf576a0, 0xc000147080, 0x1, 0x1)
	/src/repl/repl.go:865 +0xe1
github.com/open-policy-agent/opa/repl.(*REPL).evalBufferOne(0xc0001a6d80, 0x10e8600, 0xc000026050, 0x0, 0x1)
	/src/repl/repl.go:750 +0x28d
github.com/open-policy-agent/opa/repl.(*REPL).OneShot(0xc0001a6d80, 0x10e8600, 0xc000026050, 0xc000144a80, 0x17, 0x0, 0x0)
	/src/repl/repl.go:255 +0x390
github.com/open-policy-agent/opa/repl.(*REPL).Loop(0xc0001a6d80, 0x10e8600, 0xc000026050)
	/src/repl/repl.go:152 +0x33e
github.com/open-policy-agent/opa/runtime.(*Runtime).StartREPL(0xc00018ec60, 0x10e8600, 0xc000026050)
	/src/runtime/runtime.go:377 +0x3dd
github.com/open-policy-agent/opa/cmd.init.8.func1(0xc000184a00, 0x160aa90, 0x0, 0x0)
	/src/cmd/run.go:138 +0x4df
github.com/spf13/cobra.(*Command).execute(0xc000184a00, 0x160aa90, 0x0, 0x0, 0xc000184a00, 0x160aa90)
	/src/vendor/github.com/spf13/cobra/command.go:766 +0x2aa
github.com/spf13/cobra.(*Command).ExecuteC(0x1599960, 0xc000000180, 0xc0000b5f50, 0x72ed1f)
	/src/vendor/github.com/spf13/cobra/command.go:852 +0x2ea
github.com/spf13/cobra.(*Command).Execute(...)
	/src/vendor/github.com/spf13/cobra/command.go:800
main.main()
	/src/main.go:15 +0x31

We should address this at parse-time.

@tsandall tsandall added the bug label Apr 28, 2020
@tsandall tsandall self-assigned this Apr 29, 2020
tsandall added a commit to tsandall/opa that referenced this issue Apr 29, 2020
In other places where the body can be implied, the parser includes a
body containing a single "true" expression. Do the same for else.

Fixes open-policy-agent#2353

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
patrick-east pushed a commit that referenced this issue Apr 29, 2020
In other places where the body can be implied, the parser includes a
body containing a single "true" expression. Do the same for else.

Fixes #2353

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
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant