From 5ddd1dcf0f936f5bb63bb5329f14e2180cb05f51 Mon Sep 17 00:00:00 2001 From: Julien Pivotto Date: Sun, 8 Mar 2020 13:09:24 +0100 Subject: [PATCH] Fix panic when parsing varags (#6940) Signed-off-by: Julien Pivotto --- promql/parser/parse.go | 5 +++++ promql/parser/parse_test.go | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/promql/parser/parse.go b/promql/parser/parse.go index 527b5b31b4..79424dd98d 100644 --- a/promql/parser/parse.go +++ b/promql/parser/parse.go @@ -544,6 +544,11 @@ func (p *parser) checkAST(node Node) (typ ValueType) { for i, arg := range n.Args { if i >= len(n.Func.ArgTypes) { + if n.Func.Variadic == 0 { + // This is not a vararg function so we should not check the + // type of the extra arguments. + break + } i = len(n.Func.ArgTypes) - 1 } p.expectType(arg, n.Func.ArgTypes[i], fmt.Sprintf("call to function %q", n.Func.Name)) diff --git a/promql/parser/parse_test.go b/promql/parser/parse_test.go index 8de42dfdcd..f99c4762c8 100644 --- a/promql/parser/parse_test.go +++ b/promql/parser/parse_test.go @@ -2130,10 +2130,22 @@ var testExpr = []struct { input: "floor(some_metric, other_metric)", fail: true, errMsg: "expected 1 argument(s) in call to \"floor\", got 2", + }, { + input: "floor(some_metric, 1)", + fail: true, + errMsg: "expected 1 argument(s) in call to \"floor\", got 2", }, { input: "floor(1)", fail: true, errMsg: "expected type instant vector in call to function \"floor\", got scalar", + }, { + input: "hour(some_metric, some_metric, some_metric)", + fail: true, + errMsg: "expected at most 1 argument(s) in call to \"hour\", got 3", + }, { + input: "time(some_metric)", + fail: true, + errMsg: "expected 0 argument(s) in call to \"time\", got 1", }, { input: "non_existent_function_far_bar()", fail: true,