From 923368eab3d42bb6a40f9439bf7908235ef6a4ff Mon Sep 17 00:00:00 2001 From: "Victor M. Alvarez" Date: Sun, 10 Dec 2023 20:38:03 +0100 Subject: [PATCH] Prevent infinite recursion while following symlinks. Closes #2021. --- cli/yara.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cli/yara.c b/cli/yara.c index ea27646fd4..032757f994 100644 --- a/cli/yara.c +++ b/cli/yara.c @@ -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;