aboutsummaryrefslogtreecommitdiffstats
path: root/tools/fuzz.go
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2021-04-23 10:22:52 +0200
committerGitHub <noreply@github.com>2021-04-23 16:22:52 +0800
commitbee8ce342f3b6f70f6f1d54c3bf2e866f7adbb13 (patch)
tree10b60d72192f8523138f025d090863e3353cb6ed /tools/fuzz.go
parente91932bc150df1a8ae050ad5816577226283708e (diff)
downloadgitea-bee8ce342f3b6f70f6f1d54c3bf2e866f7adbb13.tar.gz
gitea-bee8ce342f3b6f70f6f1d54c3bf2e866f7adbb13.zip
Fix go-fuzz (#15596)
* Fix go-fuzz followup of https://github.com/go-gitea/gitea/pull/15175 * simplify * enhance
Diffstat (limited to 'tools/fuzz.go')
-rw-r--r--tools/fuzz.go24
1 files changed, 18 insertions, 6 deletions
diff --git a/tools/fuzz.go b/tools/fuzz.go
index 6ed1b40003..4b5b72d1d0 100644
--- a/tools/fuzz.go
+++ b/tools/fuzz.go
@@ -7,6 +7,9 @@
package fuzz
import (
+ "bytes"
+ "io"
+
"code.gitea.io/gitea/modules/markup"
"code.gitea.io/gitea/modules/markup/markdown"
)
@@ -18,17 +21,26 @@ import (
// (for example, the input is lexically correct and was parsed successfully).
// -1 if the input must not be added to corpus even if gives new coverage and 0 otherwise.
+var (
+ renderContext = markup.RenderContext{
+ URLPrefix: "https://example.com",
+ Metas: map[string]string{
+ "user": "go-gitea",
+ "repo": "gitea",
+ },
+ }
+)
+
func FuzzMarkdownRenderRaw(data []byte) int {
- _ = markdown.RenderRaw(data, "", false)
+ err := markdown.RenderRaw(&renderContext, bytes.NewReader(data), io.Discard)
+ if err != nil {
+ return 0
+ }
return 1
}
func FuzzMarkupPostProcess(data []byte) int {
- var localMetas = map[string]string{
- "user": "go-gitea",
- "repo": "gitea",
- }
- _, err := markup.PostProcess(data, "https://example.com", localMetas, false)
+ err := markup.PostProcess(&renderContext, bytes.NewReader(data), io.Discard)
if err != nil {
return 0
}