This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Don't try to compile a pattern known to be in error
[perl5.git] / toke.c
diff --git a/toke.c b/toke.c
index 383203a..880ac53 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -5021,7 +5021,16 @@ Perl_yylex(pTHX)
            s = PL_bufend;
        }
        else {
+            int save_error_count = PL_error_count;
+
            s = scan_const(PL_bufptr);
+
+            /* Quit if this was a pattern and there were errors.  This prevents
+             * us from trying to regex compile a broken pattern, which could
+             * lead to segfaults, etc. */
+            if (PL_lex_inpat && PL_error_count > save_error_count) {
+                yyquit();
+            }
            if (*s == '\\')
                PL_lex_state = LEX_INTERPCASEMOD;
            else