diff options
author | Yves Orton <demerphq@gmail.com> | 2022-08-26 18:26:14 +0200 |
---|---|---|
committer | Yves Orton <demerphq@gmail.com> | 2022-09-09 18:48:52 +0200 |
commit | eb54d46f7264ff7af62c409d8a6ab984a5a34f57 (patch) | |
tree | 87c90a0747b065f8994c54d569cb1b50eb7ae09b /perl.h | |
parent | 14580ae6b927552985b6b6294f9e836df39d0b65 (diff) | |
download | perl-eb54d46f7264ff7af62c409d8a6ab984a5a34f57.tar.gz |
Stop parsing on first syntax error.
We try to keep parsing after many types of errors, up to a (current)
maximum of 10 errors. Continuing after a semantic error (like
undeclared variables) can be helpful, for instance showing a set of
common errors, but continuing after a syntax error isn't helpful
most of the time as the internal state of the parser can get confused
and is not reliably restored in between attempts. This can produce
sometimes completely bizarre errors which just obscure the true error,
and has resulted in security tickets being filed in the past.
This patch makes the parser stop after the first syntax error, while
preserving the current behavior for other errors. An error is considered
a syntax error if the error message from our internals is the literal
text "syntax error". This may not be a complete list of true syntax
errors, we can iterate on that in the future.
This fixes the segfaults reported in Issue #17397, and #16944 and
likely fixes other "segfault due to compiler continuation after syntax
error" bugs that we have on record, which has been a recurring issue
over the years.
Diffstat (limited to 'perl.h')
-rw-r--r-- | perl.h | 6 |
1 files changed, 6 insertions, 0 deletions
@@ -8936,6 +8936,12 @@ END_EXTERN_C #define PERL_DIAG_WARN_SYNTAX(x) PERL_DIAG_STR_(x) #define PERL_DIAG_DIE_SYNTAX(x) PERL_DIAG_STR_(x) +#define PERL_STOP_PARSING_AFTER_N_ERRORS 10 + +#define PERL_PARSE_IS_SYNTAX_ERROR_FLAG 128 +#define PERL_PARSE_IS_SYNTAX_ERROR(f) ((f) & PERL_PARSE_IS_SYNTAX_ERROR_FLAG) +#define PERL_PARSE_ERROR_COUNT(f) ((f) & (PERL_PARSE_IS_SYNTAX_ERROR_FLAG-1)) + /* (KEEP THIS LAST IN perl.h!) |