From 6857da251edd416454827ac692c85de1ade6b5e6 Mon Sep 17 00:00:00 2001 From: Matt Farina Date: Fri, 15 May 2020 16:52:04 -0400 Subject: [PATCH] Catching a potential panic in strval parsing Signed-off-by: Matt Farina --- pkg/strvals/parser.go | 7 ++++++- pkg/strvals/parser_test.go | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/pkg/strvals/parser.go b/pkg/strvals/parser.go index c52f38ab1..c735412e9 100644 --- a/pkg/strvals/parser.go +++ b/pkg/strvals/parser.go @@ -150,7 +150,12 @@ func runeSet(r []rune) map[rune]bool { return s } -func (t *parser) key(data map[string]interface{}) error { +func (t *parser) key(data map[string]interface{}) (reterr error) { + defer func() { + if r := recover(); r != nil { + reterr = fmt.Errorf("unable to parse key: %s", r) + } + }() stop := runeSet([]rune{'=', '[', ',', '.'}) for { switch k, last, err := runesUntil(t.sc, stop); { diff --git a/pkg/strvals/parser_test.go b/pkg/strvals/parser_test.go index fb18980cf..742256153 100644 --- a/pkg/strvals/parser_test.go +++ b/pkg/strvals/parser_test.go @@ -362,6 +362,10 @@ func TestParseSet(t *testing.T) { }, }, }, + { + str: "]={}].", + err: true, + }, } for _, tt := range tests {