From eb54d46f7264ff7af62c409d8a6ab984a5a34f57 Mon Sep 17 00:00:00 2001 From: Yves Orton Date: Fri, 26 Aug 2022 18:26:14 +0200 Subject: 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. --- pp_ctl.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'pp_ctl.c') diff --git a/pp_ctl.c b/pp_ctl.c index c194d7b2f9..680072f0fc 100644 --- a/pp_ctl.c +++ b/pp_ctl.c @@ -1669,8 +1669,16 @@ Perl_qerror(pTHX_ SV *err) sv_catsv(PL_errors, err); else Perl_warn(aTHX_ "%" SVf, SVfARG(err)); - if (PL_parser) + + if (PL_parser) { + STRLEN len; + char *err_pv = SvPV(err,len); ++PL_parser->error_count; + if (memBEGINs(err_pv,len,"syntax error")) + { + PL_parser->error_count |= PERL_PARSE_IS_SYNTAX_ERROR_FLAG; + } + } } -- cgit v1.2.1