2020-12-10 12:43:11 -07:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
2022-11-27 11:20:29 -07:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-12-10 12:43:11 -07:00
|
|
|
|
2021-08-24 09:47:09 -07:00
|
|
|
//go:build gofuzz
|
2020-12-10 12:43:11 -07:00
|
|
|
|
|
|
|
package fuzz
|
|
|
|
|
|
|
|
import (
|
2021-04-23 01:22:52 -07:00
|
|
|
"bytes"
|
2022-01-19 16:26:57 -07:00
|
|
|
"context"
|
2021-04-23 01:22:52 -07:00
|
|
|
"io"
|
|
|
|
|
2020-12-10 12:43:11 -07:00
|
|
|
"code.gitea.io/gitea/modules/markup"
|
|
|
|
"code.gitea.io/gitea/modules/markup/markdown"
|
2021-08-12 15:22:05 -07:00
|
|
|
"code.gitea.io/gitea/modules/setting"
|
2020-12-10 12:43:11 -07: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.
|
|
|
|
|
2022-01-20 10:46:10 -07:00
|
|
|
var renderContext = markup.RenderContext{
|
|
|
|
Ctx: context.Background(),
|
|
|
|
URLPrefix: "https://example.com/go-gitea/gitea",
|
|
|
|
Metas: map[string]string{
|
|
|
|
"user": "go-gitea",
|
|
|
|
"repo": "gitea",
|
|
|
|
},
|
|
|
|
}
|
2021-04-23 01:22:52 -07:00
|
|
|
|
2020-12-10 12:43:11 -07:00
|
|
|
func FuzzMarkdownRenderRaw(data []byte) int {
|
2021-08-12 15:22:05 -07:00
|
|
|
setting.AppURL = "http://localhost:3000/"
|
2021-04-23 01:22:52 -07:00
|
|
|
err := markdown.RenderRaw(&renderContext, bytes.NewReader(data), io.Discard)
|
|
|
|
if err != nil {
|
|
|
|
return 0
|
|
|
|
}
|
2020-12-10 12:43:11 -07:00
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
func FuzzMarkupPostProcess(data []byte) int {
|
2021-08-12 15:22:05 -07:00
|
|
|
setting.AppURL = "http://localhost:3000/"
|
2021-04-23 01:22:52 -07:00
|
|
|
err := markup.PostProcess(&renderContext, bytes.NewReader(data), io.Discard)
|
2020-12-10 12:43:11 -07:00
|
|
|
if err != nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
return 1
|
|
|
|
}
|