fix(safeio): retain writable Windows parent handles
This commit is contained in:
@@ -16,15 +16,17 @@ func preflightPrivateDirectory(path string) (bool, error) {
|
||||
handle, err := openWindowsRelativeComponent(parents.handles[len(parents.handles)-1], target, true, windows.GENERIC_READ)
|
||||
if err != nil {
|
||||
if isWindowsRelativeNotFound(err) {
|
||||
writableParent, accessErr := openWindowsComponentWithAccess(
|
||||
parents.directory,
|
||||
true,
|
||||
// A read-only retained handle cannot be upgraded. Re-traverse with the
|
||||
// directory FILE_ADD_SUBDIRECTORY right, still using RootDirectory-relative
|
||||
// opens for every component rather than reopening parents by absolute path.
|
||||
writableParents, _, accessErr := openCanonicalWindowsParentWithFinalAccess(
|
||||
path,
|
||||
windows.FILE_APPEND_DATA, // FILE_ADD_SUBDIRECTORY for a directory handle
|
||||
)
|
||||
if accessErr != nil {
|
||||
if accessErr != nil || writableParents == nil {
|
||||
return false, ErrUnsafeFile
|
||||
}
|
||||
_ = windows.CloseHandle(writableParent)
|
||||
writableParents.Close()
|
||||
return false, nil
|
||||
}
|
||||
return false, ErrUnsafeFile
|
||||
|
||||
Reference in New Issue
Block a user