From be6daa5fd46edc9f66a5129347482b38e22bf103 Mon Sep 17 00:00:00 2001 From: Francis Lavoie Date: Tue, 22 Sep 2020 19:37:15 -0400 Subject: httpcaddyfile: Fix panic when parsing route with matchers (#3746) Fixes #3745 --- caddyconfig/httpcaddyfile/directives.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'caddyconfig') diff --git a/caddyconfig/httpcaddyfile/directives.go b/caddyconfig/httpcaddyfile/directives.go index e9ba44c8e..5d9a33913 100644 --- a/caddyconfig/httpcaddyfile/directives.go +++ b/caddyconfig/httpcaddyfile/directives.go @@ -304,13 +304,17 @@ func parseSegmentAsConfig(h Helper) ([]ConfigValue, error) { } // find and extract any embedded matcher definitions in this scope - for i, seg := range segments { + for i := 0; i < len(segments); i++ { + seg := segments[i] if strings.HasPrefix(seg.Directive(), matcherPrefix) { + // parse, then add the matcher to matcherDefs err := parseMatcherDefinitions(caddyfile.NewDispenser(seg), matcherDefs) if err != nil { return nil, err } + // remove the matcher segment (consumed), then step back the loop segments = append(segments[:i], segments[i+1:]...) + i-- } } -- cgit v1.2.3