2020-12-10 14:43:11 -05:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
// +build gofuzz
|
|
|
|
|
|
|
|
package fuzz
|
|
|
|
|
|
|
|
import (
|
2021-04-23 04:22:52 -04:00
|
|
|
"bytes"
|
|
|
|
"io"
|
|
|
|
|
2020-12-10 14:43:11 -05:00
|
|
|
"code.gitea.io/gitea/modules/markup"
|
|
|
|
"code.gitea.io/gitea/modules/markup/markdown"
|
2021-08-12 18:22:05 -04:00
|
|
|
"code.gitea.io/gitea/modules/setting"
|
2020-12-10 14:43:11 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// Contains fuzzing functions executed by
|
|
|
|
// fuzzing engine https://github.com/dvyukov/go-fuzz
|
|
|
|
//
|
|
|
|
// The function must return 1 if the fuzzer should increase priority of the given input during subsequent fuzzing
|
|
|
|
// (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.
|
|
|
|
|
2021-04-23 04:22:52 -04:00
|
|
|
var (
|
|
|
|
renderContext = markup.RenderContext{
|
2021-06-25 14:14:49 -04:00
|
|
|
URLPrefix: "https://example.com/go-gitea/gitea",
|
2021-04-23 04:22:52 -04:00
|
|
|
Metas: map[string]string{
|
|
|
|
"user": "go-gitea",
|
|
|
|
"repo": "gitea",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2020-12-10 14:43:11 -05:00
|
|
|
func FuzzMarkdownRenderRaw(data []byte) int {
|
2021-08-12 18:22:05 -04:00
|
|
|
setting.AppURL = "http://localhost:3000/"
|
2021-04-23 04:22:52 -04:00
|
|
|
err := markdown.RenderRaw(&renderContext, bytes.NewReader(data), io.Discard)
|
|
|
|
if err != nil {
|
|
|
|
return 0
|
|
|
|
}
|
2020-12-10 14:43:11 -05:00
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
func FuzzMarkupPostProcess(data []byte) int {
|
2021-08-12 18:22:05 -04:00
|
|
|
setting.AppURL = "http://localhost:3000/"
|
2021-04-23 04:22:52 -04:00
|
|
|
err := markup.PostProcess(&renderContext, bytes.NewReader(data), io.Discard)
|
2020-12-10 14:43:11 -05:00
|
|
|
if err != nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
return 1
|
|
|
|
}
|