From: Pascal Obry Date: Fri, 20 Nov 2020 16:28:50 +0000 (+0100) Subject: [Ada] Fix possible infinite recursion in directory iterator X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=3a6021dc1de871fc561ed0a60f1446a380d77c06;p=gcc.git [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. --- diff --git a/gcc/ada/libgnat/g-diopit.adb b/gcc/ada/libgnat/g-diopit.adb index 50bbf9b721b..1e8627e550e 100644 --- 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 index aa60d32ec96..952d795960f 100644 --- 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