Menu ▾ ▴

#110 TFileSystem.DelDirTree: a directory inside the tree that leads to a share root is entered

None
unread
nobody
2026-11-07
2026-11-07
No

Since [#109] ([r2543]) DelDirTree refuses a DirName that is the root of a volume or share by what it is, through TFileSystem.IsVolumeOrShareRoot (the final path from GetFinalPathNameByHandle, from Windows Vista on). That checks only DirName itself.

Inside the tree, a subdirectory that a server resolves to the root of its share looks like an ordinary directory, so it is not removed as a link but entered, and its contents are deleted. Example, measured with the probe of [#109] on a Samba share in WSL2: link-to-root is a symlink that Samba resolves to the share root, and Windows lists it as an ordinary directory. DelDirTree('\\server\share\work') with work\link-to-root would empty the whole share, if the share is writable. A DFS link inside the tree that points to a share root is the same case.

Possible fix: check every directory before entering it, with IsVolumeOrShareRoot, or by comparing its final path or file ID with the directory it was reached from. That costs one more open per directory; the loop guard of [#99] measured about 20 % for that on a local disk. What to do with such an entry needs deciding: skip it and leave it, remove it like a link, or stop with EDirTreeRefused.

Not measured as a deletion, for obvious reasons; a test would need a writable Samba share with such a link.

Related

Bug Reports: #109
Bug Reports: #99
Commit: [r2543]

Discussion

  • Thomas Mueller

    Thomas Mueller - 2026-11-07
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -1,4 +1,4 @@
    -Since [bugs:#109] ([r2543]) `DelDirTree` refuses a `DirName` that is the root of a volume or share by what it is, through `TFileSystem.IsVolumeOrShareRoot` (the final path from `GetFinalPathNameByHandle`, from Windows Vista on). That checks only `DirName` itself.
    +Since [#109] ([r2543]) `DelDirTree` refuses a `DirName` that is the root of a volume or share by what it is, through `TFileSystem.IsVolumeOrShareRoot` (the final path from `GetFinalPathNameByHandle`, from Windows Vista on). That checks only `DirName` itself.
    
     Inside the tree, a subdirectory that a server resolves to the root of its share looks like an ordinary directory, so it is not removed as a link but entered, and its contents are deleted. Example, measured with the probe of #109 on a Samba share in WSL2: `link-to-root` is a symlink that Samba resolves to the share root, and Windows lists it as an ordinary directory. `DelDirTree('\\server\share\work')` with `work\link-to-root` would empty the whole share, if the share is writable. A DFS link inside the tree that points to a share root is the same case.
    
    • Milestone: -->
     

    Related

    Bug Reports: #109
    Commit: [r2543]

  • Thomas Mueller

    Thomas Mueller - 2026-11-07
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -2,6 +2,6 @@
    
     Inside the tree, a subdirectory that a server resolves to the root of its share looks like an ordinary directory, so it is not removed as a link but entered, and its contents are deleted. Example, measured with the probe of #109 on a Samba share in WSL2: `link-to-root` is a symlink that Samba resolves to the share root, and Windows lists it as an ordinary directory. `DelDirTree('\\server\share\work')` with `work\link-to-root` would empty the whole share, if the share is writable. A DFS link inside the tree that points to a share root is the same case.
    
    -Possible fix: check every directory before entering it, with `IsVolumeOrShareRoot`, or by comparing its final path or file ID with the directory it was reached from. That costs one more open per directory; the loop guard of [bugs:#99] measured about 20 % for that on a local disk. What to do with such an entry needs deciding: skip it and leave it, remove it like a link, or stop with `EDirTreeRefused`.
    +Possible fix: check every directory before entering it, with `IsVolumeOrShareRoot`, or by comparing its final path or file ID with the directory it was reached from. That costs one more open per directory; the loop guard of [#99] measured about 20 % for that on a local disk. What to do with such an entry needs deciding: skip it and leave it, remove it like a link, or stop with `EDirTreeRefused`.
    
     Not measured as a deletion, for obvious reasons; a test would need a writable Samba share with such a link.
    
     

    Related

    Bug Reports: #99

  • Thomas Mueller

    Thomas Mueller - 2026-11-07
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -1,6 +1,6 @@
     Since [#109] ([r2543]) `DelDirTree` refuses a `DirName` that is the root of a volume or share by what it is, through `TFileSystem.IsVolumeOrShareRoot` (the final path from `GetFinalPathNameByHandle`, from Windows Vista on). That checks only `DirName` itself.
    
    -Inside the tree, a subdirectory that a server resolves to the root of its share looks like an ordinary directory, so it is not removed as a link but entered, and its contents are deleted. Example, measured with the probe of #109 on a Samba share in WSL2: `link-to-root` is a symlink that Samba resolves to the share root, and Windows lists it as an ordinary directory. `DelDirTree('\\server\share\work')` with `work\link-to-root` would empty the whole share, if the share is writable. A DFS link inside the tree that points to a share root is the same case.
    +Inside the tree, a subdirectory that a server resolves to the root of its share looks like an ordinary directory, so it is not removed as a link but entered, and its contents are deleted. Example, measured with the probe of [#109] on a Samba share in WSL2: `link-to-root` is a symlink that Samba resolves to the share root, and Windows lists it as an ordinary directory. `DelDirTree('\\server\share\work')` with `work\link-to-root` would empty the whole share, if the share is writable. A DFS link inside the tree that points to a share root is the same case.
    
     Possible fix: check every directory before entering it, with `IsVolumeOrShareRoot`, or by comparing its final path or file ID with the directory it was reached from. That costs one more open per directory; the loop guard of [#99] measured about 20 % for that on a local disk. What to do with such an entry needs deciding: skip it and leave it, remove it like a link, or stop with `EDirTreeRefused`.
    
     

    Related

    Bug Reports: #109
    Bug Reports: #99
    Commit: [r2543]


Log in to post a comment.