]> source.dussan.org Git - gitea.git/commitdiff
Use path not filepath in routers/editor (#14390)
authorzeripath <art27@cantab.net>
Mon, 18 Jan 2021 23:20:10 +0000 (23:20 +0000)
committerGitHub <noreply@github.com>
Mon, 18 Jan 2021 23:20:10 +0000 (00:20 +0100)
The incorrect use of filepath instead of path means that
it is possible to cause a stackoverflow on Windows

Signed-off-by: Andrew Thornton <art27@cantab.net>
routers/repo/editor.go

index afb6605dc33c9c064f9c3341061151a0f4e2e805..0bc76504f9b9e38ca7cfba88ae214b48bb03c78f 100644 (file)
@@ -9,7 +9,6 @@ import (
        "fmt"
        "io/ioutil"
        "path"
-       "path/filepath"
        "strings"
 
        "code.gitea.io/gitea/models"
@@ -502,7 +501,7 @@ func DeleteFilePost(ctx *context.Context, form auth.DeleteRepoFileForm) {
        if form.CommitChoice == frmCommitChoiceNewBranch && ctx.Repo.Repository.UnitEnabled(models.UnitTypePullRequests) {
                ctx.Redirect(ctx.Repo.RepoLink + "/compare/" + util.PathEscapeSegments(ctx.Repo.BranchName) + "..." + util.PathEscapeSegments(form.NewBranchName))
        } else {
-               treePath := filepath.Dir(ctx.Repo.TreePath)
+               treePath := path.Dir(ctx.Repo.TreePath)
                if treePath == "." {
                        treePath = "" // the file deleted was in the root, so we return the user to the root directory
                }
@@ -805,10 +804,10 @@ func GetClosestParentWithFiles(treePath string, commit *git.Commit) string {
        // see if the tree has entries
        if tree, err := commit.SubTree(treePath); err != nil {
                // failed to get tree, going up a dir
-               return GetClosestParentWithFiles(filepath.Dir(treePath), commit)
+               return GetClosestParentWithFiles(path.Dir(treePath), commit)
        } else if entries, err := tree.ListEntries(); err != nil || len(entries) == 0 {
                // no files in this dir, going up a dir
-               return GetClosestParentWithFiles(filepath.Dir(treePath), commit)
+               return GetClosestParentWithFiles(path.Dir(treePath), commit)
        }
        return treePath
 }