Browse Source

Fix go-fuzz (#15596)

* Fix go-fuzz

followup of https://github.com/go-gitea/gitea/pull/15175

* simplify

* enhance
pull/15605/head
6543 3 weeks ago
committed by GitHub
parent
commit
bee8ce342f
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 6 deletions
  1. +18
    -6
      tools/fuzz.go

+ 18
- 6
tools/fuzz.go View File

@ -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
}


Loading…
Cancel
Save