Closed 1ndahous3 closed 6 months ago
@plusvic is it ok to just remove the ECHO
macro?
The lexer.c
file is automatically generated by lex
, so we can't simply remove it. But we can define ECHO
ourselves as an empty string in lexer.h
.
@plusvic IMHO version with redefined macro is a little better in terms of output info.
With redefined macro:
error: rule "test_crash" in \test.yar(4): unterminated regular expression error: rule "test_crash" in \test.yar(4): syntax error, unexpected end of file, expecting text string
With lexer the "nodefault" option:
error: rule "test_crash" in \test.yar(3): flex scanner jammed
Absolutely, I think I'll adopt your solution then.
The bug was discovered when the CLI tool crashed while loading a simple invalid rule:
Actually MSVC CRT parameter validation failed at runtime:
I then figured out that the
ECHO
macro called with the\
symbol tries to output 1 character directly to the console. https://github.com/VirusTotal/yara/blob/01032a6cb26313e1838669418186563a4e5cfc2d/libyara/lexer.c#L1183-L1189Failed CRT runtime check:
So, if we read the
fwrite
documentation, we see a note:And the CLI tool configures the
stdout
to write UTF8 data: https://github.com/VirusTotal/yara/blob/01032a6cb26313e1838669418186563a4e5cfc2d/cli/yara.c#L1472-L1478Since
fwrite
depends on the encoding, I think writing random bytes from a buffer (rules) to stdout (or anyFILE *
) without context (right at the beginning) is a bad idea. Maybe it can just be removed?