Skip to content

Commit

Permalink
Use YR_MAX_PATH instead of MAX_PATH (#2090)
Browse files Browse the repository at this point in the history
Replace all instances of `MAX_PATH` with `YR_MAX_PATH`.
  • Loading branch information
plusvic authored Aug 1, 2024
1 parent c70d927 commit b68de47
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 24 deletions.
12 changes: 4 additions & 8 deletions cli/yara.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#define ERROR_COULD_NOT_CREATE_THREAD 100

#ifndef MAX_PATH
#define MAX_PATH 256
#endif

#ifndef min
#define min(x, y) ((x < y) ? (x) : (y))
#endif
Expand Down Expand Up @@ -491,9 +487,9 @@ static bool is_directory(const char_t* path)
static int scan_dir(const char_t* dir, SCAN_OPTIONS* scan_opts)
{
int result = ERROR_SUCCESS;
char_t path[MAX_PATH];
char_t path[YR_MAX_PATH];

_sntprintf(path, MAX_PATH, _T("%s\\*"), dir);
_sntprintf(path, YR_MAX_PATH, _T("%s\\*"), dir);

WIN32_FIND_DATA FindFileData;
HANDLE hFind = FindFirstFile(path, &FindFileData);
Expand All @@ -502,7 +498,7 @@ static int scan_dir(const char_t* dir, SCAN_OPTIONS* scan_opts)
{
do
{
_sntprintf(path, MAX_PATH, _T("%s\\%s"), dir, FindFileData.cFileName);
_sntprintf(path, YR_MAX_PATH, _T("%s\\%s"), dir, FindFileData.cFileName);

if (!(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
Expand Down Expand Up @@ -673,7 +669,7 @@ static int scan_dir(const char* dir, SCAN_OPTIONS* scan_opts)

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

snprintf(full_path, sizeof(full_path), "%s/%s", dir, de->d_name);
Expand Down
4 changes: 0 additions & 4 deletions cli/yarac.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "args.h"
#include "common.h"

#ifndef MAX_PATH
#define MAX_PATH 256
#endif

#define MAX_ARGS_EXT_VAR 32

#define exit_with_code(code) \
Expand Down
9 changes: 5 additions & 4 deletions libyara/include/yara/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,10 @@ typedef struct _YR_EXPRESSION
YR_ARENA_REF sized_string_ref;
} value;

// Boolean expressions can hold a string count. If not empty, this indicates that the condition
// can only be fulfilled if at least so many strings match.
struct {
// Boolean expressions can hold a string count. If not empty, this indicates
// that the condition can only be fulfilled if at least so many strings match.
struct
{
int count;
} required_strings;

Expand Down Expand Up @@ -288,7 +289,7 @@ typedef struct _YR_COMPILER
char* lex_buf_ptr;
unsigned short lex_buf_len;

char include_base_dir[MAX_PATH];
char include_base_dir[YR_MAX_PATH];
void* user_data;
void* incl_clbk_user_data;
void* re_ast_clbk_user_data;
Expand Down
7 changes: 3 additions & 4 deletions libyara/include/yara/limits.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include "utils.h"

// Maximum length of file paths. This is the only limit that doesn't have the
// YR_ prefix. The intention is using the default MAX_PATH if defined.
#ifndef MAX_PATH
#define MAX_PATH 1024
// Maximum length of file paths.
#ifndef YR_MAX_PATH
#define YR_MAX_PATH 4096
#endif

// Maximum number of threads that can use a YR_RULES structure simultaneously.
Expand Down
5 changes: 3 additions & 2 deletions libyara/modules/pe/pe.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include <yara/dotnet.h>
#include <yara/endian.h>
#include <yara/limits.h>
#include <yara/mem.h>
#include <yara/modules.h>
#include <yara/pe.h>
Expand Down Expand Up @@ -366,9 +367,9 @@ static void pe_parse_debug_directory(PE* pe)
if (pdb_path != NULL)
{
pdb_path_len = strnlen(
pdb_path, yr_min(available_space(pe, pdb_path), MAX_PATH));
pdb_path, yr_min(available_space(pe, pdb_path), YR_MAX_PATH));

if (pdb_path_len >= 0 && pdb_path_len < MAX_PATH)
if (pdb_path_len >= 0 && pdb_path_len < YR_MAX_PATH)
{
yr_set_sized_string(pdb_path, pdb_path_len, pe->object, "pdb_path");
break;
Expand Down
4 changes: 2 additions & 2 deletions libyara/proc/linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ typedef struct _YR_PROC_INFO
uint64_t map_offset;
uint64_t next_block_end;
int page_size;
char map_path[PATH_MAX];
char map_path[YR_MAX_PATH];
uint64_t map_dmaj;
uint64_t map_dmin;
uint64_t map_ino;
Expand Down Expand Up @@ -327,7 +327,7 @@ YR_API YR_MEMORY_BLOCK* yr_process_get_next_memory_block(
YR_PROC_ITERATOR_CTX* context = (YR_PROC_ITERATOR_CTX*) iterator->context;
YR_PROC_INFO* proc_info = (YR_PROC_INFO*) context->proc_info;

char buffer[PATH_MAX];
char buffer[YR_MAX_PATH];
char perm[5];

uint64_t begin, end;
Expand Down

0 comments on commit b68de47

Please sign in to comment.