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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. package fuzz
  6. import (
  7. "bytes"
  8. "context"
  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 renderContext = markup.RenderContext{
  21. Ctx: context.Background(),
  22. URLPrefix: "https://example.com/go-gitea/gitea",
  23. Metas: map[string]string{
  24. "user": "go-gitea",
  25. "repo": "gitea",
  26. },
  27. }
  28. func FuzzMarkdownRenderRaw(data []byte) int {
  29. setting.AppURL = "http://localhost:3000/"
  30. err := markdown.RenderRaw(&renderContext, bytes.NewReader(data), io.Discard)
  31. if err != nil {
  32. return 0
  33. }
  34. return 1
  35. }
  36. func FuzzMarkupPostProcess(data []byte) int {
  37. setting.AppURL = "http://localhost:3000/"
  38. err := markup.PostProcess(&renderContext, bytes.NewReader(data), io.Discard)
  39. if err != nil {
  40. return 0
  41. }
  42. return 1
  43. }