You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

fuzz.go 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright 2020 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. //go:build gofuzz
  5. // +build gofuzz
  6. package fuzz
  7. import (
  8. "bytes"
  9. "io"
  10. "code.gitea.io/gitea/modules/markup"
  11. "code.gitea.io/gitea/modules/markup/markdown"
  12. "code.gitea.io/gitea/modules/setting"
  13. )
  14. // Contains fuzzing functions executed by
  15. // fuzzing engine https://github.com/dvyukov/go-fuzz
  16. //
  17. // The function must return 1 if the fuzzer should increase priority of the given input during subsequent fuzzing
  18. // (for example, the input is lexically correct and was parsed successfully).
  19. // -1 if the input must not be added to corpus even if gives new coverage and 0 otherwise.
  20. var (
  21. renderContext = markup.RenderContext{
  22. URLPrefix: "https://example.com/go-gitea/gitea",
  23. Metas: map[string]string{
  24. "user": "go-gitea",
  25. "repo": "gitea",
  26. },
  27. }
  28. )
  29. func FuzzMarkdownRenderRaw(data []byte) int {
  30. setting.AppURL = "http://localhost:3000/"
  31. err := markdown.RenderRaw(&renderContext, bytes.NewReader(data), io.Discard)
  32. if err != nil {
  33. return 0
  34. }
  35. return 1
  36. }
  37. func FuzzMarkupPostProcess(data []byte) int {
  38. setting.AppURL = "http://localhost:3000/"
  39. err := markup.PostProcess(&renderContext, bytes.NewReader(data), io.Discard)
  40. if err != nil {
  41. return 0
  42. }
  43. return 1
  44. }