Skip to content

Commit

Permalink
ast/parser: fix nightly fuzz case (#5330)
Browse files Browse the repository at this point in the history
An unchecked ref had made it into RefHead() in one of the parsers
code paths. Now, it's rejected as it should be.

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
  • Loading branch information
srenatus committed Nov 2, 2022
1 parent a855ab1 commit 94f8bc7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 4 additions & 0 deletions ast/parser.go
Expand Up @@ -802,6 +802,10 @@ func (p *Parser) parseHead(defaultRule bool) (*Head, bool) {
case Var:
ref = Ref{op}
case Ref:
if _, ok := y[0].Value.(Var); !ok {
p.illegal("rule head ref %v invalid", y)
return nil, false
}
ref = y
}
head = RefHead(ref)
Expand Down
4 changes: 3 additions & 1 deletion ast/parser_test.go
Expand Up @@ -2150,7 +2150,9 @@ func TestRuleRefHeads(t *testing.T) {
})
}

// TODO(sr): error cases, non-ground terms anywhere but at the end of the ref
assertParseErrorContains(t, "first ref head term is call", `package p
q(0).r(0) { true }`,
"unexpected { token: rule head ref q(0).r invalid", opts)
}

func TestRuleElseKeyword(t *testing.T) {
Expand Down

0 comments on commit 94f8bc7

Please sign in to comment.