mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-31 10:13:14 -04:00 
			
		
		
		
	fix(caddyfile): infinite loop on unclosed braces (#7571)
Update coredns/caddy to a version where Dispenser.NextBlock() checks Next() and stops at EOF. This ensures forward progress and prevents an infinite loop when a block is missing a closing '}' under certain conditions. Added a regression test. Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
This commit is contained in:
		| @@ -4,21 +4,44 @@ import ( | ||||
| 	"testing" | ||||
| ) | ||||
|  | ||||
| func TestCorefile1(t *testing.T) { | ||||
| 	defer func() { | ||||
| 		if r := recover(); r != nil { | ||||
| 			t.Fatalf("Expected no panic, but got %v", r) | ||||
| 		} | ||||
| 	}() | ||||
|  | ||||
| 	// this used to crash | ||||
| 	corefile := `\\\\ȶ. | ||||
| // TestCorefileParsing tests the Corefile parsing functionality. | ||||
| // Expected to not panic or timeout. | ||||
| func TestCorefileParsing(t *testing.T) { | ||||
| 	cases := []struct { | ||||
| 		name     string | ||||
| 		corefile string | ||||
| 	}{ | ||||
| 		{ | ||||
| 			// See: https://github.com/coredns/coredns/pull/4637 | ||||
| 			name: "PR4637_" + "NoPanicOnEscapedBackslashesAndUnicode", | ||||
| 			corefile: `\\\\ȶ. | ||||
| acl | ||||
| ` | ||||
| 	i, _, _, _ := CoreDNSServerAndPorts(corefile) | ||||
| 	defer func() { | ||||
| 		if i != nil { | ||||
| 			i.Stop() | ||||
| 		} | ||||
| 	}() | ||||
| `, | ||||
| 		}, | ||||
| 		{ | ||||
| 			// See: https://github.com/coredns/coredns/pull/7571 | ||||
| 			name: "PR7571_" + "InvalidBlockFailsToStart", | ||||
| 			corefile: "\xD9//\n" + | ||||
| 				"hosts#\x90\xD0{lc\x0C{\n" + | ||||
| 				"'{mport\xEF1\x0C}\x0B''", | ||||
| 		}, | ||||
| 	} | ||||
|  | ||||
| 	for _, tc := range cases { | ||||
| 		t.Run(tc.name, func(t *testing.T) { | ||||
| 			defer func() { | ||||
| 				if r := recover(); r != nil { | ||||
| 					t.Fatalf("Expected no panic, but got %v", r) | ||||
| 				} | ||||
| 			}() | ||||
|  | ||||
| 			i, _, _, _ := CoreDNSServerAndPorts(tc.corefile) | ||||
|  | ||||
| 			defer func() { | ||||
| 				if i != nil { | ||||
| 					i.Stop() | ||||
| 				} | ||||
| 			}() | ||||
| 		}) | ||||
| 	} | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user