Skip to content

Commit bee8ce3

Browse files
authored
Fix go-fuzz (#15596)
* Fix go-fuzz followup of #15175 * simplify * enhance
1 parent e91932b commit bee8ce3

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

tools/fuzz.go

+18-6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
package fuzz
88

99
import (
10+
"bytes"
11+
"io"
12+
1013
"code.gitea.io/gitea/modules/markup"
1114
"code.gitea.io/gitea/modules/markup/markdown"
1215
)
@@ -18,17 +21,26 @@ import (
1821
// (for example, the input is lexically correct and was parsed successfully).
1922
// -1 if the input must not be added to corpus even if gives new coverage and 0 otherwise.
2023

24+
var (
25+
renderContext = markup.RenderContext{
26+
URLPrefix: "https://example.com",
27+
Metas: map[string]string{
28+
"user": "go-gitea",
29+
"repo": "gitea",
30+
},
31+
}
32+
)
33+
2134
func FuzzMarkdownRenderRaw(data []byte) int {
22-
_ = markdown.RenderRaw(data, "", false)
35+
err := markdown.RenderRaw(&renderContext, bytes.NewReader(data), io.Discard)
36+
if err != nil {
37+
return 0
38+
}
2339
return 1
2440
}
2541

2642
func FuzzMarkupPostProcess(data []byte) int {
27-
var localMetas = map[string]string{
28-
"user": "go-gitea",
29-
"repo": "gitea",
30-
}
31-
_, err := markup.PostProcess(data, "https://example.com", localMetas, false)
43+
err := markup.PostProcess(&renderContext, bytes.NewReader(data), io.Discard)
3244
if err != nil {
3345
return 0
3446
}

0 commit comments

Comments
 (0)