Skip to content

Commit 923368e

Browse files
committed
Prevent infinite recursion while following symlinks.
Closes VirusTotal#2021.
1 parent cddec11 commit 923368e

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

cli/yara.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -688,14 +688,15 @@ static int scan_dir(const char* dir, SCAN_OPTIONS* scan_opts)
688688
de = readdir(dp);
689689
continue;
690690
}
691-
// If the directory entry is a symlink, check if it points to . and
692-
// skip it in that case.
691+
// If the directory entry is a symlink, check if it points to . or .. and
692+
// skip it in those cases.
693693
else if (S_ISLNK(st.st_mode))
694694
{
695695
char buf[2];
696696
int len = readlink(full_path, buf, sizeof(buf));
697697

698-
if (len == 1 && buf[0] == '.')
698+
if ((len == 1 && buf[0] == '.') ||
699+
(len == 2 && buf[0] == '.' && buf[1] == '.'))
699700
{
700701
de = readdir(dp);
701702
continue;

0 commit comments

Comments
 (0)