Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
plusvic committed Apr 4, 2022
1 parent d7e8be3 commit b47b60d
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 14 deletions.
7 changes: 6 additions & 1 deletion libyara/hex_lexer.c
Original file line number Diff line number Diff line change
Expand Up @@ -2484,7 +2484,12 @@ int yr_parse_hex_string(

(*re_ast)->flags |= RE_FLAGS_DOT_ALL;

yylex_init(&yyscanner);
if (yylex_init(&yyscanner) != 0)
{
yr_re_ast_destroy(*re_ast);
return ERROR_INSUFFICIENT_MEMORY;
}

yyset_extra(*re_ast, yyscanner);
yy_scan_string(hex_string, yyscanner);
yyparse(yyscanner, &lex_env);
Expand Down
7 changes: 6 additions & 1 deletion libyara/hex_lexer.l
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,12 @@ int yr_parse_hex_string(

(*re_ast)->flags |= RE_FLAGS_DOT_ALL;

yylex_init(&yyscanner);
if (yylex_init(&yyscanner) != 0)
{
yr_re_ast_destroy(*re_ast);
return ERROR_INSUFFICIENT_MEMORY;
}

yyset_extra(*re_ast, yyscanner);
yy_scan_string(hex_string, yyscanner);
yyparse(yyscanner, &lex_env);
Expand Down
26 changes: 21 additions & 5 deletions libyara/lexer.c
Original file line number Diff line number Diff line change
Expand Up @@ -3588,10 +3588,15 @@ int yr_lex_parse_rules_string(

compiler->errors = 0;

if (setjmp(compiler->error_recovery) != 0)
if (yylex_init(&yyscanner) != 0)
{
compiler->errors = 1;
compiler->last_error = ERROR_INSUFFICIENT_MEMORY;
return compiler->errors;
}

yylex_init(&yyscanner);
if (setjmp(compiler->error_recovery) != 0)
return compiler->errors;

#if YYDEBUG
yydebug = 1;
Expand All @@ -3615,10 +3620,15 @@ int yr_lex_parse_rules_file(

compiler->errors = 0;

if (setjmp(compiler->error_recovery) != 0)
if (yylex_init(&yyscanner) != 0)
{
compiler->errors = 1;
compiler->last_error = ERROR_INSUFFICIENT_MEMORY;
return compiler->errors;
}

yylex_init(&yyscanner);
if (setjmp(compiler->error_recovery) != 0)
return compiler->errors;

#if YYDEBUG
yydebug = 1;
Expand Down Expand Up @@ -3684,7 +3694,13 @@ int yr_lex_parse_rules_fd(
return compiler->errors;
}

yylex_init(&yyscanner);
if (yylex_init(&yyscanner) != 0)
{
yr_free(buffer);
compiler->errors = 1;
compiler->last_error = ERROR_INSUFFICIENT_MEMORY;
return compiler->errors;
}

#if YYDEBUG
yydebug = 1;
Expand Down
26 changes: 21 additions & 5 deletions libyara/lexer.l
Original file line number Diff line number Diff line change
Expand Up @@ -896,10 +896,15 @@ int yr_lex_parse_rules_string(

compiler->errors = 0;

if (setjmp(compiler->error_recovery) != 0)
if (yylex_init(&yyscanner) != 0)
{
compiler->errors = 1;
compiler->last_error = ERROR_INSUFFICIENT_MEMORY;
return compiler->errors;
}

yylex_init(&yyscanner);
if (setjmp(compiler->error_recovery) != 0)
return compiler->errors;

#if YYDEBUG
yydebug = 1;
Expand All @@ -923,10 +928,15 @@ int yr_lex_parse_rules_file(

compiler->errors = 0;

if (setjmp(compiler->error_recovery) != 0)
if (yylex_init(&yyscanner) != 0)
{
compiler->errors = 1;
compiler->last_error = ERROR_INSUFFICIENT_MEMORY;
return compiler->errors;
}

yylex_init(&yyscanner);
if (setjmp(compiler->error_recovery) != 0)
return compiler->errors;

#if YYDEBUG
yydebug = 1;
Expand Down Expand Up @@ -992,7 +1002,13 @@ int yr_lex_parse_rules_fd(
return compiler->errors;
}

yylex_init(&yyscanner);
if (yylex_init(&yyscanner) != 0)
{
yr_free(buffer);
compiler->errors = 1;
compiler->last_error = ERROR_INSUFFICIENT_MEMORY;
return compiler->errors;
}

#if YYDEBUG
yydebug = 1;
Expand Down
7 changes: 6 additions & 1 deletion libyara/re_lexer.c
Original file line number Diff line number Diff line change
Expand Up @@ -2871,7 +2871,12 @@ int yr_parse_re_string(

FAIL_ON_ERROR(yr_re_ast_create(re_ast));

yylex_init(&yyscanner);
if (yylex_init(&yyscanner) != 0)
{
yr_re_ast_destroy(*re_ast);
return ERROR_INSUFFICIENT_MEMORY;
}

yyset_extra(*re_ast, yyscanner);
yy_scan_string(re_string, yyscanner);
yyparse(yyscanner, &lex_env);
Expand Down
7 changes: 6 additions & 1 deletion libyara/re_lexer.l
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,12 @@ int yr_parse_re_string(

FAIL_ON_ERROR(yr_re_ast_create(re_ast));

yylex_init(&yyscanner);
if (yylex_init(&yyscanner) != 0)
{
yr_re_ast_destroy(*re_ast);
return ERROR_INSUFFICIENT_MEMORY;
}

yyset_extra(*re_ast, yyscanner);
yy_scan_string(re_string, yyscanner);
yyparse(yyscanner, &lex_env);
Expand Down

0 comments on commit b47b60d

Please sign in to comment.