When the directory iterator Find is called we need to ensure that
symbolic links are skipped to avoid possible circularities or exploring
unrelated directories.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

        * libgnat/g-diopit.adb (Find): Fix possible infinite recursion
        in Find iterator.
        * libgnat/g-diopit.ads (Find): Update comments accordingly.
diff --git a/gcc/ada/libgnat/g-diopit.adb b/gcc/ada/libgnat/g-diopit.adb
--- a/gcc/ada/libgnat/g-diopit.adb
+++ b/gcc/ada/libgnat/g-diopit.adb
@@ -32,6 +32,7 @@
 with Ada.Characters.Handling;
 with Ada.Strings.Fixed;
 with Ada.Strings.Maps;
+
 with GNAT.OS_Lib;
 with GNAT.Regexp;
 
@@ -49,7 +50,7 @@ package body GNAT.Directory_Operations.Iteration is
    is
       File_Regexp : constant Regexp.Regexp := Regexp.Compile (File_Pattern);
       Index       : Natural := 0;
-      Quit        : Boolean;
+      Quit        : Boolean := False;
 
       procedure Read_Directory (Directory : Dir_Name_Str);
       --  Open Directory and read all entries. This routine is called
@@ -113,6 +114,7 @@ package body GNAT.Directory_Operations.Iteration is
 
                if not (Dir_Entry = "." or else Dir_Entry = "..")
                  and then OS_Lib.Is_Directory (Pathname)
+                 and then not OS_Lib.Is_Symbolic_Link (Pathname)
                then
                   Read_Directory (Pathname);
                   exit when Quit;
@@ -124,7 +126,6 @@ package body GNAT.Directory_Operations.Iteration is
       end Read_Directory;
 
    begin
-      Quit := False;
       Read_Directory (Root_Directory);
    end Find;
 


diff --git a/gcc/ada/libgnat/g-diopit.ads b/gcc/ada/libgnat/g-diopit.ads
--- a/gcc/ada/libgnat/g-diopit.ads
+++ b/gcc/ada/libgnat/g-diopit.ads
@@ -50,6 +50,8 @@ package GNAT.Directory_Operations.Iteration is
    --  will pass in the value False on each call to Action. The iterator will
    --  terminate after passing the last matched path to Action or after
    --  returning from a call to Action which sets Quit to True.
+   --  The iterator does not follow symbolic links avoiding possible
+   --  circularities or exploring unrelated directories.
    --  Raises GNAT.Regexp.Error_In_Regexp if File_Pattern is ill formed.
 
    generic


Reply via email to