From 2d7f9345eb2888ce793bb26c993cd2f086f10972 Mon Sep 17 00:00:00 2001 From: AdamKorcz Date: Thu, 3 Dec 2020 14:40:18 +0000 Subject: [PATCH 1/7] Added fuzzer Signed-off-by: AdamKorcz --- fuzz/fuzz.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 fuzz/fuzz.go diff --git a/fuzz/fuzz.go b/fuzz/fuzz.go new file mode 100644 index 0000000000000..c8ec422964255 --- /dev/null +++ b/fuzz/fuzz.go @@ -0,0 +1,29 @@ +// 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 ( + "code.gitea.io/gitea/modules/markup" + "code.gitea.io/gitea/modules/markup/markdown" +) + +func Fuzz(data []byte) int { + _ = markdown.RenderRaw(data, "", false) + return 1 +} + +func Fuzz2(data []byte) int { + var localMetas = map[string]string{ + "user": "gogits", + "repo": "gogs", + } + _, err := markup.PostProcess(data, "/tmp", localMetas, false) + if err != nil { + return 0 + } + return 1 +} From d6e3cabcccd63a24d6dd5503a6fb5426db698f51 Mon Sep 17 00:00:00 2001 From: AdamKorcz Date: Thu, 3 Dec 2020 15:18:10 +0000 Subject: [PATCH 2/7] Added better fuzzer names Signed-off-by: AdamKorcz --- fuzz/fuzz.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fuzz/fuzz.go b/fuzz/fuzz.go index c8ec422964255..55290402dce5a 100644 --- a/fuzz/fuzz.go +++ b/fuzz/fuzz.go @@ -11,12 +11,12 @@ import ( "code.gitea.io/gitea/modules/markup/markdown" ) -func Fuzz(data []byte) int { +func FuzzMarkdownRenderRaw(data []byte) int { _ = markdown.RenderRaw(data, "", false) return 1 } -func Fuzz2(data []byte) int { +func FuzzMarkupPostProcess(data []byte) int { var localMetas = map[string]string{ "user": "gogits", "repo": "gogs", From 1a95d7762201725f51212f112083e1f2f846a3fd Mon Sep 17 00:00:00 2001 From: AdamKorcz Date: Thu, 3 Dec 2020 20:41:27 +0000 Subject: [PATCH 3/7] Moved fuzzer to /tools --- {fuzz => tools}/fuzz.go | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {fuzz => tools}/fuzz.go (100%) diff --git a/fuzz/fuzz.go b/tools/fuzz.go similarity index 100% rename from fuzz/fuzz.go rename to tools/fuzz.go From 8c8744facfd40fb97bd5782388791ed64f1ccc78 Mon Sep 17 00:00:00 2001 From: AdamKorcz <44787359+AdamKorcz@users.noreply.github.com> Date: Fri, 4 Dec 2020 15:41:39 +0000 Subject: [PATCH 4/7] Update tools/fuzz.go Co-authored-by: 6543 <6543@obermui.de> --- tools/fuzz.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tools/fuzz.go b/tools/fuzz.go index 55290402dce5a..6553e6b075463 100644 --- a/tools/fuzz.go +++ b/tools/fuzz.go @@ -11,6 +11,13 @@ import ( "code.gitea.io/gitea/modules/markup/markdown" ) +// 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. + func FuzzMarkdownRenderRaw(data []byte) int { _ = markdown.RenderRaw(data, "", false) return 1 From 280ffada8bab5b000af264d37c82170e7bc99139 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Wed, 9 Dec 2020 14:28:53 +0000 Subject: [PATCH 5/7] Update tools/fuzz.go --- tools/fuzz.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/fuzz.go b/tools/fuzz.go index 6553e6b075463..bb4cc88dd559e 100644 --- a/tools/fuzz.go +++ b/tools/fuzz.go @@ -25,8 +25,8 @@ func FuzzMarkdownRenderRaw(data []byte) int { func FuzzMarkupPostProcess(data []byte) int { var localMetas = map[string]string{ - "user": "gogits", - "repo": "gogs", + "user": "go-gitea", + "repo": "gitea", } _, err := markup.PostProcess(data, "/tmp", localMetas, false) if err != nil { From cf9941e39380e62295f7905b79296f1ddca02ada Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Wed, 9 Dec 2020 15:11:45 +0000 Subject: [PATCH 6/7] Update tools/fuzz.go Co-authored-by: silverwind --- tools/fuzz.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/fuzz.go b/tools/fuzz.go index bb4cc88dd559e..6ed1b40003d8c 100644 --- a/tools/fuzz.go +++ b/tools/fuzz.go @@ -28,7 +28,7 @@ func FuzzMarkupPostProcess(data []byte) int { "user": "go-gitea", "repo": "gitea", } - _, err := markup.PostProcess(data, "/tmp", localMetas, false) + _, err := markup.PostProcess(data, "https://example.com", localMetas, false) if err != nil { return 0 } From 39cab0ba30488e2af584711f2f252814f9f60491 Mon Sep 17 00:00:00 2001 From: AdamKorcz Date: Thu, 10 Dec 2020 18:44:49 +0000 Subject: [PATCH 7/7] Added tools to Makefile --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 0e33047aa25f4..e21cf20f84f82 100644 --- a/Makefile +++ b/Makefile @@ -110,7 +110,7 @@ TAGS ?= TAGS_SPLIT := $(subst $(COMMA), ,$(TAGS)) TAGS_EVIDENCE := $(MAKE_EVIDENCE_DIR)/tags -GO_DIRS := cmd integrations models modules routers build services vendor +GO_DIRS := cmd integrations models modules routers build services vendor tools GO_SOURCES := $(wildcard *.go) GO_SOURCES += $(shell find $(GO_DIRS) -type f -name "*.go" -not -path modules/options/bindata.go -not -path modules/public/bindata.go -not -path modules/templates/bindata.go)