Set a max size for the logql parser to 5k. (#3471)

* Set a max size for the logql parser to 5k.

The API anyway receives the query via querystring which is normally max out by 2k based on RFC2616.
This will improve fuzzing too.

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>

* better error.

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
pull/3484/head
Cyril Tovena 5 years ago committed by GitHub
parent c49e807a55
commit 64decdbcb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      pkg/logql/parser.go

@ -2,6 +2,7 @@ package logql
import (
"errors"
"fmt"
"sort"
"strings"
"sync"
@ -22,6 +23,8 @@ var parserPool = sync.Pool{
},
}
const maxInputSize = 5120
func init() {
// Improve the error messages coming out of yacc.
exprErrorVerbose = true
@ -53,6 +56,10 @@ func (p *parser) Parse() (Expr, error) {
// ParseExpr parses a string and returns an Expr.
func ParseExpr(input string) (expr Expr, err error) {
if len(input) >= maxInputSize {
return nil, newParseError(fmt.Sprintf("input size too long (%d > %d)", len(input), maxInputSize), 0, 0)
}
defer func() {
if r := recover(); r != nil {
var ok bool
@ -64,6 +71,7 @@ func ParseExpr(input string) (expr Expr, err error) {
}
}
}()
p := parserPool.Get().(*parser)
defer parserPool.Put(p)

Loading…
Cancel
Save