Skip to content
Snippets Groups Projects
Commit 3a6021dc authored by Pascal Obry's avatar Pascal Obry Committed by Pierre-Marie de Rodat
Browse files

[Ada] Fix possible infinite recursion in directory iterator

gcc/ada/

	* libgnat/g-diopit.adb (Find): Fix possible infinite recursion
	in Find iterator.
	* libgnat/g-diopit.ads (Find): Update comments accordingly.
parent afed612d
No related branches found
No related tags found
No related merge requests found
......@@ -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;
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment