Skip to content

Commit

Permalink
Redefine ECHO macro to not print unmatched text to the console
Browse files Browse the repository at this point in the history
  • Loading branch information
1ndahous3 committed Nov 25, 2023
1 parent 01032a6 commit a752f57
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions libyara/include/yara/hex_lexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion libyara/include/yara/lexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)


Expand Down
4 changes: 4 additions & 0 deletions libyara/include/yara/re_lexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit a752f57

Please sign in to comment.