sftp: terminate the missing-ancestor permission walk at the root

A path whose ancestors are all absent recursed on the root forever,
since Dir("/") is "/".

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
Chris LuandDevin committed 2026-10-12 02:41:28 -07:00
1 parent 2c031d9d63
commit 6bac506842
1 file changed
+3
+3
View File
@@ -67,6 +67,9 @@ func (fs *SftpServer) CheckFilePermission(path string, perm string) error {
// check permissions on the parent directory instead
if err == os.ErrNotExist {
parentPath := stdpath.Dir(path)
if parentPath == path {
return os.ErrPermission
}
// Check if user can write to the parent directory
return fs.CheckFilePermission(parentPath, perm)
}