Skip to content

Commit

Permalink
Prevent infinite recursion while following symlinks.
Browse files Browse the repository at this point in the history
Closes #2021.
  • Loading branch information
plusvic committed Dec 10, 2023
1 parent cddec11 commit 923368e
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions cli/yara.c
Original file line number Diff line number Diff line change
Expand Up @@ -688,14 +688,15 @@ static int scan_dir(const char* dir, SCAN_OPTIONS* scan_opts)
de = readdir(dp);
continue;
}
// If the directory entry is a symlink, check if it points to . and
// skip it in that case.
// If the directory entry is a symlink, check if it points to . or .. and
// skip it in those cases.
else if (S_ISLNK(st.st_mode))
{
char buf[2];
int len = readlink(full_path, buf, sizeof(buf));

if (len == 1 && buf[0] == '.')
if ((len == 1 && buf[0] == '.') ||
(len == 2 && buf[0] == '.' && buf[1] == '.'))
{
de = readdir(dp);
continue;
Expand Down

0 comments on commit 923368e

Please sign in to comment.