mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 16:40:24 +08:00 
			
		
		
		
	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> Co-authored-by: zeripath <art27@cantab.net> Co-authored-by: Lauris BH <lauris@nix.lv>
This commit is contained in:
		@@ -9,7 +9,6 @@ import (
 | 
				
			|||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"io/ioutil"
 | 
						"io/ioutil"
 | 
				
			||||||
	"path"
 | 
						"path"
 | 
				
			||||||
	"path/filepath"
 | 
					 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"code.gitea.io/gitea/models"
 | 
						"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) {
 | 
						if form.CommitChoice == frmCommitChoiceNewBranch && ctx.Repo.Repository.UnitEnabled(models.UnitTypePullRequests) {
 | 
				
			||||||
		ctx.Redirect(ctx.Repo.RepoLink + "/compare/" + ctx.Repo.BranchName + "..." + form.NewBranchName)
 | 
							ctx.Redirect(ctx.Repo.RepoLink + "/compare/" + ctx.Repo.BranchName + "..." + form.NewBranchName)
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		treePath := filepath.Dir(ctx.Repo.TreePath)
 | 
							treePath := path.Dir(ctx.Repo.TreePath)
 | 
				
			||||||
		if treePath == "." {
 | 
							if treePath == "." {
 | 
				
			||||||
			treePath = "" // the file deleted was in the root, so we return the user to the root directory
 | 
								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
 | 
						// see if the tree has entries
 | 
				
			||||||
	if tree, err := commit.SubTree(treePath); err != nil {
 | 
						if tree, err := commit.SubTree(treePath); err != nil {
 | 
				
			||||||
		// failed to get tree, going up a dir
 | 
							// 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 {
 | 
						} else if entries, err := tree.ListEntries(); err != nil || len(entries) == 0 {
 | 
				
			||||||
		// no files in this dir, going up a dir
 | 
							// no files in this dir, going up a dir
 | 
				
			||||||
		return GetClosestParentWithFiles(filepath.Dir(treePath), commit)
 | 
							return GetClosestParentWithFiles(path.Dir(treePath), commit)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return treePath
 | 
						return treePath
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user