TFileSearcher: first attempt to try to avoid circular links (infinite loop when recuring directories).

Part of issue #40689.
This commit is contained in:
Bart 2024-01-23 23:43:45 +01:00
parent 9f02bfab4a
commit 7b1e04c5d8

View File

@ -863,7 +863,13 @@ var
if (PathInfo.Name = '.') or (PathInfo.Name = '..') or
(PathInfo.Name = '') or ((PathInfo.Attr and faDirectory) = 0) or
(not FFollowSymLink and FileIsSymlink(APath + PathInfo.Name)) or
(not AcceptDir(APath+PathInfo.Name))
(FileIsSymlink(APath + PathInfo.Name) and
( //try to detect the simples case of a circular link
//is the link "up or down the current tree": infinite loop if we follow
FileIsInPath(ExpandFilenameUTF8(ReadAllLinks(APath+PathInfo.Name,False)),ExpandFilenameUTF8(APath)) or
FileIsInPath(ExpandFilenameUTF8(APath),ExpandFilenameUTF8(ReadAllLinks(APath+PathInfo.Name,False))))
) or
(not AcceptDir(PathInfo.Name))
then Continue;
FPath := APath;