[BUGFIX] PromQL: avoid panic parsing malformed info call (#17379)

Signed-off-by: Linas Medziunas <linas.medziunas@gmail.com>
This commit is contained in:
Linas Medžiūnas 2025-10-23 09:42:19 +02:00 committed by GitHub
parent 3d2d847e77
commit b2e7938e25
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 3 deletions

View File

@ -803,11 +803,14 @@ func (p *parser) checkAST(node Node) (typ ValueType) {
p.addParseErrf(node.PositionRange(), "expected type %s in %s, got %s", DocumentedType(ValueTypeVector), fmt.Sprintf("call to function %q", n.Func.Name), DocumentedType(n.Args[1].Type()))
}
// Check the vector selector in the input doesn't contain a metric name
if n.Args[1].(*VectorSelector).Name != "" {
if vs, ok := n.Args[1].(*VectorSelector); ok && vs.Name != "" {
p.addParseErrf(n.Args[1].PositionRange(), "expected label selectors only, got vector selector instead")
} else if ok {
// Set Vector Selector flag to bypass empty matcher check
vs.BypassEmptyMatcherCheck = true
} else {
p.addParseErrf(n.Args[1].PositionRange(), "expected label selectors only")
}
// Set Vector Selector flag to bypass empty matcher check
n.Args[1].(*VectorSelector).BypassEmptyMatcherCheck = true
}
for i, arg := range n.Args {

View File

@ -4375,6 +4375,17 @@ var testExpr = []struct {
PosRange: posrange.PositionRange{Start: 0, End: 73},
},
},
{
input: `info(http_request_counter_total{namespace="zzz"}, {foo="bar"} == 1)`,
fail: true,
errors: ParseErrors{
ParseErr{
PositionRange: posrange.PositionRange{Start: 50, End: 66},
Err: errors.New("expected label selectors only"),
Query: `info(http_request_counter_total{namespace="zzz"}, {foo="bar"} == 1)`,
},
},
},
// Test that nested parentheses result in the correct position range.
{
input: `foo[11s+10s-5*2^2]`,