Skip to content

Commit

Permalink
Fix go-fuzz (#15596)
Browse files Browse the repository at this point in the history
* Fix go-fuzz

followup of #15175

* simplify

* enhance
  • Loading branch information
6543 committed Apr 23, 2021
1 parent e91932b commit bee8ce3
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions tools/fuzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
package fuzz

import (
"bytes"
"io"

"code.gitea.io/gitea/modules/markup"
"code.gitea.io/gitea/modules/markup/markdown"
)
Expand All @@ -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
}
Expand Down

0 comments on commit bee8ce3

Please sign in to comment.