Skip to content

Commit

Permalink
Do not follow symlinks
Browse files Browse the repository at this point in the history
Signed-off-by: onox <[email protected]>
Fixes: #2
  • Loading branch information
onox committed Dec 5, 2019
1 parent 13b2cf6 commit 983cd20
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/inotify-recursive.adb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ package body Inotify.Recursive is
end if;
exception
-- Ignore the folder if the user has no permission to scan it
-- or if the file is a symlink
when Ada.IO_Exceptions.Use_Error =>
null;
end Add_Entry;
Expand All @@ -54,6 +55,11 @@ package body Inotify.Recursive is
Recursive_Mask.Moved_To := True;
Recursive_Mask.Moved_Self := True;

-- Do not follow symlinks
if Ada.Directories.Full_Name (Path) /= Path then
raise Ada.IO_Exceptions.Use_Error;
end if;

Ada.Directories.Search (Path, "", Process => Add_Entry'Access);
return Result : constant Watch := Instance (Object).Add_Watch (Path, Recursive_Mask) do
Object.Masks.Insert (Result.Watch, Mask);
Expand Down
6 changes: 3 additions & 3 deletions src/inotify-recursive.ads
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ package Inotify.Recursive is
Mask : Watch_Bits := All_Events) return Watch;
-- Watch the given path and any subdirectories
--
-- If the user has no permission to read the folder at the given path,
-- then a Use_Error is raised. Any subdirectory, however, is ignored
-- if it is not readable.
-- If the user has no permission to read the folder at the given path
-- or if the path is a symlink, then a Use_Error is raised. Any
-- subdirectory, however, is ignored if it is not readable or is a symlink.

overriding
procedure Remove_Watch (Object : in out Recursive_Instance; Subject : Watch);
Expand Down

0 comments on commit 983cd20

Please sign in to comment.