Repository: caddyserver/caddy (language: go)

Issue:
fuzz-format: Timeout in fuzz-format
Detailed Report: https://oss-fuzz.com/testcase?key=5957507767926784

Project: caddy
Fuzzing Engine: libFuzzer
Fuzz Target: fuzz-format
Job Type: libfuzzer_asan_caddy
Platform Id: linux

Crash Type: Timeout (exceeds 60 secs)
Crash Address: 
Crash State:
  fuzz-format
  
Sanitizer: address (ASAN)

Regressed: https://oss-fuzz.com/revisions?job=libfuzzer_asan_caddy&range=202401210622:202401220608

Reproducer Testcase: https://oss-fuzz.com/download?testcase_id=5957507767926784

Issue on oss-fuzz tracker: [Issue 66099](https://crbug.com/oss-fuzz/66099)

Minimized reproducer test case: [clusterfuzz-testcase-minimized-fuzz-format-5957507767926784.txt](https://github.com/caddyserver/caddy/files/14036540/clusterfuzz-testcase-minimized-fuzz-format-5957507767926784.txt)



Discussion / hints:
FYI @bbaa-bbaa we might have an infinite loop in the formatter

Fix patch:
diff --git a/caddyconfig/caddyfile/formatter.go b/caddyconfig/caddyfile/formatter.go
index 18753c65e36..764f7911802 100644
--- a/caddyconfig/caddyfile/formatter.go
+++ b/caddyconfig/caddyfile/formatter.go
@@ -18,6 +18,8 @@ import (
 	"bytes"
 	"io"
 	"unicode"
+
+	"golang.org/x/exp/slices"
 )
 
 // Format formats the input Caddyfile to a standard, nice-looking
@@ -128,7 +130,7 @@ func Format(input []byte) []byte {
 				heredocClosingMarker = heredocClosingMarker[1:]
 			}
 			// check if we're done
-			if string(heredocClosingMarker) == string(heredocMarker) {
+			if slices.Equal(heredocClosingMarker, heredocMarker) {
 				heredocMarker = nil
 				heredocClosingMarker = nil
 				heredoc = heredocClosed


Test patch: