Skip to content

Commit d2d99a2

Browse files
6543zeripath
andauthored
Fix NPE in fuzzer (#16680) (#16682)
The fuzzer found an issue with the issue pattern processor where there is a spurious path.Clean which does not need to be there. This PR also sets the default AppURL for the fuzzer too. Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: zeripath <art27@cantab.net>
1 parent e483ec8 commit d2d99a2

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

Diff for: modules/markup/html.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ func fullIssuePatternProcessor(ctx *RenderContext, node *html.Node) {
778778

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

Diff for: modules/markup/html_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package markup_test
66

77
import (
8+
"io"
89
"strings"
910
"testing"
1011

@@ -526,3 +527,18 @@ func BenchmarkEmojiPostprocess(b *testing.B) {
526527
assert.NoError(b, err)
527528
}
528529
}
530+
531+
func TestFuzz(t *testing.T) {
532+
s := "t/l/issues/8#/../../a"
533+
renderContext := RenderContext{
534+
URLPrefix: "https://example.com/go-gitea/gitea",
535+
Metas: map[string]string{
536+
"user": "go-gitea",
537+
"repo": "gitea",
538+
},
539+
}
540+
541+
err := PostProcess(&renderContext, strings.NewReader(s), io.Discard)
542+
543+
assert.NoError(t, err)
544+
}

Diff for: tools/fuzz.go

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
"code.gitea.io/gitea/modules/markup"
1414
"code.gitea.io/gitea/modules/markup/markdown"
15+
"code.gitea.io/gitea/modules/setting"
1516
)
1617

1718
// Contains fuzzing functions executed by
@@ -32,6 +33,7 @@ var (
3233
)
3334

3435
func FuzzMarkdownRenderRaw(data []byte) int {
36+
setting.AppURL = "http://localhost:3000/"
3537
err := markdown.RenderRaw(&renderContext, bytes.NewReader(data), io.Discard)
3638
if err != nil {
3739
return 0
@@ -40,6 +42,7 @@ func FuzzMarkdownRenderRaw(data []byte) int {
4042
}
4143

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

0 commit comments

Comments
 (0)