From a752f57eb377a1bfb6b416453c71c81540482c8e Mon Sep 17 00:00:00 2001 From: Roman <9205230+1ndahous3@users.noreply.github.com> Date: Sat, 25 Nov 2023 16:14:09 +0300 Subject: [PATCH 1/2] Redefine ECHO macro to not print unmatched text to the console --- libyara/include/yara/hex_lexer.h | 3 +++ libyara/include/yara/lexer.h | 9 ++++++++- libyara/include/yara/re_lexer.h | 4 ++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/libyara/include/yara/hex_lexer.h b/libyara/include/yara/hex_lexer.h index 588adf384b..d6ea0c8336 100644 --- a/libyara/include/yara/hex_lexer.h +++ b/libyara/include/yara/hex_lexer.h @@ -53,6 +53,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define yyget_extra hex_yyget_extra #define yyget_lineno hex_yyget_lineno +// The default code for unmatched text text is the ECHO macro, which write it to the console. +// It's not safe to print random bytes because it may cause the calling program to terminate. +#define ECHO #ifndef YY_TYPEDEF_YY_SCANNER_T #define YY_TYPEDEF_YY_SCANNER_T diff --git a/libyara/include/yara/lexer.h b/libyara/include/yara/lexer.h index 5a90ab3c0e..87aa21e4f2 100644 --- a/libyara/include/yara/lexer.h +++ b/libyara/include/yara/lexer.h @@ -55,6 +55,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define yyget_extra yara_yyget_extra #define yyget_lineno yara_yyget_lineno +// The default code for unmatched text text is the ECHO macro, which write it to the console. +// It's not safe to print random bytes because it may cause the calling program to terminate. +#define ECHO #ifndef YY_TYPEDEF_YY_SCANNER_T #define YY_TYPEDEF_YY_SCANNER_T @@ -67,7 +70,11 @@ union YYSTYPE; int yylex( \ union YYSTYPE* yylval_param, yyscan_t yyscanner, YR_COMPILER* compiler) - +// The default behavior when a fatal error occurs in the parser is calling +// exit(YY_EXIT_FAILURE) for terminating the process. This is not acceptable +// for a library, which should return gracefully to the calling program. For +// this reason we redefine the YY_FATAL_ERROR macro so that it expands to our +// own function instead of the one provided by default. #define YY_FATAL_ERROR(msg) yara_yyfatal(yyscanner, msg) diff --git a/libyara/include/yara/re_lexer.h b/libyara/include/yara/re_lexer.h index 930e31ab93..4232710f07 100644 --- a/libyara/include/yara/re_lexer.h +++ b/libyara/include/yara/re_lexer.h @@ -53,6 +53,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define yyget_extra re_yyget_extra #define yyget_lineno re_yyget_lineno +// The default code for unmatched text text is the ECHO macro, which write it to the console. +// It's not safe to print random bytes because it may cause the calling program to terminate. +#define ECHO + #ifndef YY_TYPEDEF_YY_SCANNER_T #define YY_TYPEDEF_YY_SCANNER_T typedef void* yyscan_t; From d7e18d74a2ef1c04d62e94e6a090868621fdb061 Mon Sep 17 00:00:00 2001 From: Roman <9205230+1ndahous3@users.noreply.github.com> Date: Sat, 25 Nov 2023 17:03:02 +0300 Subject: [PATCH 2/2] fix typo --- libyara/include/yara/hex_lexer.h | 2 +- libyara/include/yara/lexer.h | 2 +- libyara/include/yara/re_lexer.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libyara/include/yara/hex_lexer.h b/libyara/include/yara/hex_lexer.h index d6ea0c8336..4c0b60025a 100644 --- a/libyara/include/yara/hex_lexer.h +++ b/libyara/include/yara/hex_lexer.h @@ -53,7 +53,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define yyget_extra hex_yyget_extra #define yyget_lineno hex_yyget_lineno -// The default code for unmatched text text is the ECHO macro, which write it to the console. +// The default code for unmatched text is the ECHO macro, which write it to the console. // It's not safe to print random bytes because it may cause the calling program to terminate. #define ECHO diff --git a/libyara/include/yara/lexer.h b/libyara/include/yara/lexer.h index 87aa21e4f2..7e8aa97921 100644 --- a/libyara/include/yara/lexer.h +++ b/libyara/include/yara/lexer.h @@ -55,7 +55,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define yyget_extra yara_yyget_extra #define yyget_lineno yara_yyget_lineno -// The default code for unmatched text text is the ECHO macro, which write it to the console. +// The default code for unmatched text is the ECHO macro, which write it to the console. // It's not safe to print random bytes because it may cause the calling program to terminate. #define ECHO diff --git a/libyara/include/yara/re_lexer.h b/libyara/include/yara/re_lexer.h index 4232710f07..eb82b8610b 100644 --- a/libyara/include/yara/re_lexer.h +++ b/libyara/include/yara/re_lexer.h @@ -53,7 +53,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define yyget_extra re_yyget_extra #define yyget_lineno re_yyget_lineno -// The default code for unmatched text text is the ECHO macro, which write it to the console. +// The default code for unmatched text is the ECHO macro, which write it to the console. // It's not safe to print random bytes because it may cause the calling program to terminate. #define ECHO