Merge pull request #2854 from prometheus/promql-rune

Check for invalid utf-8 in lexer strings.
This commit is contained in:
Fabian Reinartz 2017-06-17 14:42:20 +02:00 committed by GitHub
commit f46a8e9ea4
3 changed files with 19 additions and 0 deletions

View file

@ -713,6 +713,8 @@ Loop:
switch l.next() { switch l.next() {
case '\\': case '\\':
lexEscape(l) lexEscape(l)
case utf8.RuneError:
return l.errorf("invalid UTF-8 rune")
case eof, '\n': case eof, '\n':
return l.errorf("unterminated quoted string") return l.errorf("unterminated quoted string")
case l.stringOpen: case l.stringOpen:
@ -728,6 +730,8 @@ func lexRawString(l *lexer) stateFn {
Loop: Loop:
for { for {
switch l.next() { switch l.next() {
case utf8.RuneError:
return l.errorf("invalid UTF-8 rune")
case eof: case eof:
return l.errorf("unterminated raw string") return l.errorf("unterminated raw string")
case l.stringOpen: case l.stringOpen:

View file

@ -396,6 +396,13 @@ var tests = []struct {
}, { }, {
input: `]`, fail: true, input: `]`, fail: true,
}, },
// Test encoding issues.
{
input: "\"\xff\"", fail: true,
},
{
input: "`\xff`", fail: true,
},
// Test series description. // Test series description.
{ {
input: `{} _ 1 x .3`, input: `{} _ 1 x .3`,

View file

@ -904,6 +904,10 @@ var testExpr = []struct {
// TODO(fabxc): willingly lexing wrong tokens allows for more precrise error // TODO(fabxc): willingly lexing wrong tokens allows for more precrise error
// messages from the parser - consider if this is an option. // messages from the parser - consider if this is an option.
errMsg: "unexpected character inside braces: '>'", errMsg: "unexpected character inside braces: '>'",
}, {
input: "some_metric{a=\"\xff\"}",
fail: true,
errMsg: "parse error at char 15: invalid UTF-8 rune",
}, { }, {
input: `foo{gibberish}`, input: `foo{gibberish}`,
fail: true, fail: true,
@ -1373,6 +1377,10 @@ var testExpr = []struct {
input: "rate(some_metric)", input: "rate(some_metric)",
fail: true, fail: true,
errMsg: "expected type range vector in call to function \"rate\", got instant vector", errMsg: "expected type range vector in call to function \"rate\", got instant vector",
}, {
input: "label_replace(a, `b`, `c\xff`, `d`, `.*`)",
fail: true,
errMsg: "parse error at char 23: invalid UTF-8 rune",
}, },
// Fuzzing regression tests. // Fuzzing regression tests.
{ {