Skip to content

Commit

Permalink
Use path not filepath in routers/editor (go-gitea#14390) (go-gitea#14396
Browse files Browse the repository at this point in the history
)

The incorrect use of filepath instead of path means that
it is possible to cause a stackoverflow on Windows

Signed-off-by: Andrew Thornton <[email protected]>

Co-authored-by: zeripath <[email protected]>
Co-authored-by: Lauris BH <[email protected]>
  • Loading branch information
3 people authored Jan 19, 2021
1 parent 4583caa commit 0c3f950
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions routers/repo/editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"fmt"
"io/ioutil"
"path"
"path/filepath"
"strings"

"code.gitea.io/gitea/models"
Expand Down Expand Up @@ -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/" + ctx.Repo.BranchName + "..." + 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
}
Expand Down Expand Up @@ -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
}

0 comments on commit 0c3f950

Please sign in to comment.