Skip to content

Commit

Permalink
Mitigate stack overflow when scanning very deep directory trees.
Browse files Browse the repository at this point in the history
Closes #2088.
  • Loading branch information
plusvic committed Aug 1, 2024
1 parent be2212a commit 2a9f61d
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions cli/yara.c
Original file line number Diff line number Diff line change
Expand Up @@ -667,12 +667,14 @@ static int scan_dir(const char* dir, SCAN_OPTIONS* scan_opts)
{
struct dirent* de = readdir(dp);

char* full_path = calloc(YR_MAX_PATH, sizeof(char));
const size_t full_path_size = YR_MAX_PATH * sizeof(char);

while (de && result != ERROR_SCAN_TIMEOUT)
{
char full_path[YR_MAX_PATH];
struct stat st;

snprintf(full_path, sizeof(full_path), "%s/%s", dir, de->d_name);
snprintf(full_path, full_path_size, "%s/%s", dir, de->d_name);

int err = lstat(full_path, &st);

Expand Down Expand Up @@ -731,6 +733,7 @@ static int scan_dir(const char* dir, SCAN_OPTIONS* scan_opts)
de = readdir(dp);
}

free(full_path);
closedir(dp);
}

Expand Down

0 comments on commit 2a9f61d

Please sign in to comment.