diff --git a/MAINTAINERS b/MAINTAINERS index 926a308d1eb6c..e3357f7b8fe44 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -45,3 +45,4 @@ Janis Estelmann (@KN4CK3R) Steven Kriegler (@justusbunsi) Jimmy Praet (@jpraet) Leon Hofmeister (@delvh) +Gusted 6 && line[4] == 'a' { + // The shortest string that can end up here is: + // "--- a\t\n" without the qoutes. + // This line has a len() of 7 but doesn't contain a oldName. + // So the amount that the line need is at least 8 or more. + // The code will otherwise panic for a out-of-bounds. + if len(line) > 7 && line[4] == 'a' { curFile.OldName = line[6 : len(line)-1] if line[len(line)-2] == '\t' { curFile.OldName = curFile.OldName[:len(curFile.OldName)-1] @@ -1194,6 +1199,11 @@ func readFileName(rd *strings.Reader) (string, bool) { _ = rd.UnreadByte() if char == '"' { fmt.Fscanf(rd, "%q ", &name) + if len(name) == 0 { + log.Error("Reader has no file name: %v", rd) + return "", true + } + if name[0] == '\\' { name = name[1:] } diff --git a/services/gitdiff/gitdiff_test.go b/services/gitdiff/gitdiff_test.go index d69d0c01d8df8..6decb59b64b5a 100644 --- a/services/gitdiff/gitdiff_test.go +++ b/services/gitdiff/gitdiff_test.go @@ -541,3 +541,22 @@ func TestDiffToHTML_14231(t *testing.T) { assertEqual(t, expected, output) } + +func TestNoCrashes(t *testing.T) { + type testcase struct { + gitdiff string + } + + tests := []testcase{ + { + gitdiff: "diff --git \n--- a\t\n", + }, + { + gitdiff: "diff --git \"0\n", + }, + } + for _, testcase := range tests { + // It shouldn't crash, so don't care about the output. + ParsePatch(setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(testcase.gitdiff)) + } +} diff --git a/web_src/js/features/comp/ImagePaste.js b/web_src/js/features/comp/ImagePaste.js index 30c5820f62f99..f7f076bf80546 100644 --- a/web_src/js/features/comp/ImagePaste.js +++ b/web_src/js/features/comp/ImagePaste.js @@ -1,4 +1,4 @@ -const {appSubUrl, csrfToken} = window.config; +const {csrfToken} = window.config; async function uploadFile(file, uploadUrl) { const formData = new FormData(); @@ -67,7 +67,7 @@ export function initCompImagePaste($target) { const name = img.name.substr(0, img.name.lastIndexOf('.')); insertAtCursor(textarea, `![${name}]()`); const data = await uploadFile(img, uploadUrl); - replaceAndKeepCursor(textarea, `![${name}]()`, `![${name}](${appSubUrl}/attachments/${data.uuid})`); + replaceAndKeepCursor(textarea, `![${name}]()`, `![${name}](/attachments/${data.uuid})`); const input = $(``).val(data.uuid); dropzoneFiles.appendChild(input[0]); } @@ -83,7 +83,7 @@ export function initSimpleMDEImagePaste(simplemde, dropzone, files) { const name = img.name.substr(0, img.name.lastIndexOf('.')); const data = await uploadFile(img, uploadUrl); const pos = simplemde.codemirror.getCursor(); - simplemde.codemirror.replaceRange(`![${name}](${appSubUrl}/attachments/${data.uuid})`, pos); + simplemde.codemirror.replaceRange(`![${name}](/attachments/${data.uuid})`, pos); const input = $(``).val(data.uuid); files.append(input); }