Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 11, 14:45 UTC
fix(caddyfile): Prevent parser to panic when no token were added by empty {block} (#7543)
prettysunflower committed
Mar 3, 2026 at 13:16 UTC
2dd3852416e2b04bc90b98643673ec9e131c32e6
3 files changed
+68
-1
caddyconfig/caddyfile/parse.go
+1
-1
@@ -507,7 +507,7 @@ func (p *parser) doImport(nesting int) error {
507
// format, won't check for nesting correctness or any other error, that's what parser does.
508
if !maybeSnippet && nesting == 0 {
509
// first of the line
510
- if i == 0 || isNextOnNewLine(tokensCopy[i-1], token) {
510
+ if i == 0 || isNextOnNewLine(tokensCopy[len(tokensCopy)-1], token) {
511
index = 0
512
} else {
513
index++
caddytest/integration/caddyfile_adapt/import_block_snippet_non_replaced_block_from_separate_file.caddyfiletest
new
+52
@@ -0,0 +1,52 @@
1
+import testdata/issue_7518_unused_block_panic_snippets.conf
2
+
3
+example.com {
4
+ import snippet
5
+}
6
+----------
7
+{
8
+ "apps": {
9
+ "http": {
10
+ "servers": {
11
+ "srv0": {
12
+ "listen": [
13
+ ":443"
14
+ ],
15
+ "routes": [
16
+ {
17
+ "match": [
18
+ {
19
+ "host": [
20
+ "example.com"
21
+ ]
22
+ }
23
+ ],
24
+ "handle": [
25
+ {
26
+ "handler": "subroute",
27
+ "routes": [
28
+ {
29
+ "handle": [
30
+ {
31
+ "handler": "headers",
32
+ "response": {
33
+ "set": {
34
+ "Reverse_proxy": [
35
+ "localhost:3000"
36
+ ]
37
+ }
38
+ }
39
+ }
40
+ ]
41
+ }
42
+ ]
43
+ }
44
+ ],
45
+ "terminal": true
46
+ }
47
+ ]
48
+ }
49
+ }
50
+ }
51
+ }
52
+}
\ No newline at end of file
caddytest/integration/testdata/issue_7518_unused_block_panic_snippets.conf
new
+15
@@ -0,0 +1,15 @@
1
+# Used by import_block_snippet_non_replaced_block_from_separate_file.caddyfiletest
2
+
3
+(snippet) {
4
+ header {
5
+ reverse_proxy localhost:3000
6
+ {block}
7
+ }
8
+}
9
+
10
+# This snippet being unused by the test Caddyfile is intentional.
11
+# This is to test that a panic runtime error triggered by an out-of-range slice index access
12
+# will not happen again, please see issue #7518 and pull request #7543 for more information
13
+(unused_snippet) {
14
+ header SomeHeader SomeValue
15
+}
\ No newline at end of file