Browse Source

* don't recurse findfirst/next if filename = . or ..
closes #40722

marcoonthegit 1 year ago
parent
commit
56eb1e03ee
1 changed files with 2 additions and 1 deletions
  1. 2 1
      packages/vcl-compat/src/system.ioutils.pp

+ 2 - 1
packages/vcl-compat/src/system.ioutils.pp

@@ -2155,7 +2155,8 @@ begin
   Result      :=[];
   Result      :=[];
   if (FindFirst(IntPath + aSearchPattern, TFile.FileAttributesToInteger(SearchAttributes), SearchRec) = 0) then
   if (FindFirst(IntPath + aSearchPattern, TFile.FileAttributesToInteger(SearchAttributes), SearchRec) = 0) then
     repeat
     repeat
-      if (aSearchOption = TSearchOption.soAllDirectories) and ((SearchRec.Attr and {$IFDEF FPC_DOTTEDUNITS}System.{$ENDIF}SysUtils.faDirectory) <> 0) then
+      if (aSearchOption = TSearchOption.soAllDirectories) and ((SearchRec.Attr and {$IFDEF FPC_DOTTEDUNITS}System.{$ENDIF}SysUtils.faDirectory) <> 0)
+         and (SearchRec.Name <> '.') and (SearchRec.Name <> '..') then
         Result:=Result + GetFilesAndDirectories(IntPath + SearchRec.Name, aSearchPattern, aSearchOption, SearchAttributes, aPredicate)
         Result:=Result + GetFilesAndDirectories(IntPath + SearchRec.Name, aSearchPattern, aSearchOption, SearchAttributes, aPredicate)
       else if FilterPredicate(aPath, SearchRec) then
       else if FilterPredicate(aPath, SearchRec) then
         Result:=Result + [IntPath + SearchRec.Name];
         Result:=Result + [IntPath + SearchRec.Name];