mirror of
https://github.com/prometheus/prometheus.git
synced 2025-08-06 14:17:12 +02:00
fix: prevent invalid array access in aggregate expression
This commit fixes the evaluation of invalid expressions like
`sum(rate(`. Before that, it would trigger a panic in the PromQL engine
because it tried to access an index which is out of range.
The bug was probably introduced by 06d0b063ea
.
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
This commit is contained in:
parent
f69c83f5f1
commit
71217a6e43
@ -451,6 +451,11 @@ func (p *parser) newAggregateExpr(op Item, modifier, args Node) (ret *AggregateE
|
|||||||
ret = modifier.(*AggregateExpr)
|
ret = modifier.(*AggregateExpr)
|
||||||
arguments := args.(Expressions)
|
arguments := args.(Expressions)
|
||||||
|
|
||||||
|
if len(p.closingParens) == 0 {
|
||||||
|
// Prevents invalid array accesses.
|
||||||
|
// The error is already captured by the parser.
|
||||||
|
return
|
||||||
|
}
|
||||||
ret.PosRange = posrange.PositionRange{
|
ret.PosRange = posrange.PositionRange{
|
||||||
Start: op.Pos,
|
Start: op.Pos,
|
||||||
End: p.closingParens[0],
|
End: p.closingParens[0],
|
||||||
|
@ -4540,6 +4540,11 @@ var testExpr = []struct {
|
|||||||
PosRange: posrange.PositionRange{Start: 0, End: 20},
|
PosRange: posrange.PositionRange{Start: 0, End: 20},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
input: "sum(rate(",
|
||||||
|
fail: true,
|
||||||
|
errMsg: "unclosed left parenthesis",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeInt64Pointer(val int64) *int64 {
|
func makeInt64Pointer(val int64) *int64 {
|
||||||
|
Loading…
Reference in New Issue
Block a user