From fc667aaafdb51d160e0f4dd770e2e3b130d9ce2f Mon Sep 17 00:00:00 2001 From: Matthias Hanel Date: Fri, 8 Jan 2021 13:17:19 -0500 Subject: [PATCH] [fiixed] infinite loop in config parser for include with quote and double quote Signed-off-by: Matthias Hanel --- conf/lex.go | 4 ++++ conf/parse_test.go | 10 ++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/conf/lex.go b/conf/lex.go index 49ca743a..390ef734 100644 --- a/conf/lex.go +++ b/conf/lex.go @@ -413,6 +413,8 @@ func lexIncludeQuotedString(lx *lexer) stateFn { lx.next() lx.ignore() return lx.pop() + case r == eof: + return lx.errorf("Unexpected EOF in quoted include") } return lexIncludeQuotedString } @@ -429,6 +431,8 @@ func lexIncludeDubQuotedString(lx *lexer) stateFn { lx.next() lx.ignore() return lx.pop() + case r == eof: + return lx.errorf("Unexpected EOF in double quoted include") } return lexIncludeDubQuotedString } diff --git a/conf/parse_test.go b/conf/parse_test.go index 427aeba1..37d533fc 100644 --- a/conf/parse_test.go +++ b/conf/parse_test.go @@ -385,9 +385,11 @@ func TestIncludeVariablesWithChecks(t *testing.T) { } func TestParserNoInfiniteLoop(t *testing.T) { - if _, err := Parse(`A@@Føøøø?˛ø:{øøøø˙˙`); err == nil { - t.Fatal("expected an error") - } else if !strings.Contains(err.Error(), "Unexpected EOF") { - t.Fatal("expected unexpected eof error") + for _, test := range []string{`A@@Føøøø?˛ø:{øøøø˙˙`, `include "9/�`} { + if _, err := Parse(test); err == nil { + t.Fatal("expected an error") + } else if !strings.Contains(err.Error(), "Unexpected EOF") { + t.Fatal("expected unexpected eof error") + } } }