From 94f8bc7206eac1391a9f1f0d50f44f45add59c40 Mon Sep 17 00:00:00 2001 From: Stephan Renatus Date: Wed, 2 Nov 2022 10:00:14 +0100 Subject: [PATCH] ast/parser: fix nightly fuzz case (#5330) 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 --- ast/parser.go | 4 ++++ ast/parser_test.go | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ast/parser.go b/ast/parser.go index 88732fe64a..8bf96f0803 100644 --- a/ast/parser.go +++ b/ast/parser.go @@ -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) diff --git a/ast/parser_test.go b/ast/parser_test.go index 4d610f9249..aa4e76d571 100644 --- a/ast/parser_test.go +++ b/ast/parser_test.go @@ -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) {