Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NPE in fuzzer #16680

Merged
merged 1 commit into from
Aug 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/markup/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ func fullIssuePatternProcessor(ctx *RenderContext, node *html.Node) {

// extract repo and org name from matched link like
// http://localhost:3000/gituser/myrepo/issues/1
linkParts := strings.Split(path.Clean(link), "/")
linkParts := strings.Split(link, "/")
matchOrg := linkParts[len(linkParts)-4]
matchRepo := linkParts[len(linkParts)-3]

Expand Down
16 changes: 16 additions & 0 deletions modules/markup/html_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package markup_test

import (
"io"
"strings"
"testing"

Expand Down Expand Up @@ -526,3 +527,18 @@ func BenchmarkEmojiPostprocess(b *testing.B) {
assert.NoError(b, err)
}
}

func TestFuzz(t *testing.T) {
s := "t/l/issues/8#/../../a"
renderContext := RenderContext{
URLPrefix: "https://example.com/go-gitea/gitea",
Metas: map[string]string{
"user": "go-gitea",
"repo": "gitea",
},
}

err := PostProcess(&renderContext, strings.NewReader(s), io.Discard)

assert.NoError(t, err)
}
3 changes: 3 additions & 0 deletions tools/fuzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"code.gitea.io/gitea/modules/markup"
"code.gitea.io/gitea/modules/markup/markdown"
"code.gitea.io/gitea/modules/setting"
)

// Contains fuzzing functions executed by
Expand All @@ -32,6 +33,7 @@ var (
)

func FuzzMarkdownRenderRaw(data []byte) int {
setting.AppURL = "http://localhost:3000/"
6543 marked this conversation as resolved.
Show resolved Hide resolved
err := markdown.RenderRaw(&renderContext, bytes.NewReader(data), io.Discard)
if err != nil {
return 0
Expand All @@ -40,6 +42,7 @@ func FuzzMarkdownRenderRaw(data []byte) int {
}

func FuzzMarkupPostProcess(data []byte) int {
setting.AppURL = "http://localhost:3000/"
err := markup.PostProcess(&renderContext, bytes.NewReader(data), io.Discard)
if err != nil {
return 0
Expand Down