@marcel91200 / caddy Mirror · read-only / commits / 7103ea09
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 12, 23:15 UTC

caddyfile: Fix case where heredoc marker is empty after newline (#5769)

Fixes `panic: runtime error: slice bounds out of range [:3] with capacity 2` Co-authored-by: Matt Holt <mholt@users.noreply.github.com>

Francis Lavoie committed Aug 23, 2023 at 23:27 UTC 7103ea096fffd851a5efd67fd6d30cf65bc38873
2 files changed +9
caddyconfig/caddyfile/lexer.go
+4
@@ -154,6 +154,10 @@ func (l *lexer) next() (bool, error) {
154 // we reset the val because the heredoc is syntax we don't
155 // want to keep.
156 if ch == '\n' {
157 + if len(val) == 2 {
158 + return false, fmt.Errorf("missing opening heredoc marker on line #%d; must contain only alpha-numeric characters, dashes and underscores; got empty string", l.line)
159 + }
160 +
161 // check if there's too many <
162 if string(val[:3]) == "<<<" {
163 return false, fmt.Errorf("too many '<' for heredoc on line #%d; only use two, for example <<END", l.line)
caddyconfig/caddyfile/lexer_test.go
+5
@@ -409,6 +409,11 @@ EOF same-line-arg
409 },
410 },
411 },
412 + {
413 + input: []byte("not-a-heredoc <<\n"),
414 + expectErr: true,
415 + errorMessage: "missing opening heredoc marker on line #1; must contain only alpha-numeric characters, dashes and underscores; got empty string",
416 + },
417 {
418 input: []byte(`heredoc <<<EOF
419 content