8cee2a9
From 817480137a8b1165315f21d14b8968862101c3a2 Mon Sep 17 00:00:00 2001
8cee2a9
From: Tony Cook <tony@develop-help.com>
8cee2a9
Date: Tue, 28 Aug 2018 14:11:10 +1000
8cee2a9
Subject: [PATCH] (perl #132158) abort compilation if we see an error compiling
8cee2a9
 a form
8cee2a9
MIME-Version: 1.0
8cee2a9
Content-Type: text/plain; charset=UTF-8
8cee2a9
Content-Transfer-Encoding: 8bit
8cee2a9
8cee2a9
Signed-off-by: Petr Písař <ppisar@redhat.com>
8cee2a9
---
8cee2a9
 t/lib/croak/toke | 9 +++++++++
8cee2a9
 toke.c           | 9 +++++++++
8cee2a9
 2 files changed, 18 insertions(+)
8cee2a9
8cee2a9
diff --git a/t/lib/croak/toke b/t/lib/croak/toke
8cee2a9
index 59c377ba6b..21851229fe 100644
8cee2a9
--- a/t/lib/croak/toke
8cee2a9
+++ b/t/lib/croak/toke
8cee2a9
@@ -493,3 +493,12 @@ sub t1 {}
8cee2a9
 sub t2 (}
8cee2a9
 EXPECT
8cee2a9
 Prototype not terminated at - line 2.
8cee2a9
+########
8cee2a9
+# NAME [perl #132158] format with syntax errors
8cee2a9
+format=
8cee2a9
+@
8cee2a9
+=h
8cee2a9
+=cut
8cee2a9
+EXPECT
8cee2a9
+syntax error at - line 4, next token ???
8cee2a9
+Execution of - aborted due to compilation errors.
8cee2a9
diff --git a/toke.c b/toke.c
8cee2a9
index 844de04a23..666424ba02 100644
8cee2a9
--- a/toke.c
8cee2a9
+++ b/toke.c
8cee2a9
@@ -5099,6 +5099,14 @@ Perl_yylex(pTHX)
8cee2a9
 
8cee2a9
 	return yylex();
8cee2a9
     case LEX_FORMLINE:
8cee2a9
+        if (PL_parser->sub_error_count != PL_error_count) {
8cee2a9
+            /* There was an error parsing a formline, which tends to
8cee2a9
+               mess up the parser.
8cee2a9
+               Unlike interpolated sub-parsing, we can't treat any of
8cee2a9
+               these as recoverable, so no need to check sub_no_recover.
8cee2a9
+            */
8cee2a9
+            yyquit();
8cee2a9
+        }
8cee2a9
 	assert(PL_lex_formbrack);
8cee2a9
 	s = scan_formline(PL_bufptr);
8cee2a9
 	if (!PL_lex_formbrack)
8cee2a9
@@ -6518,6 +6526,7 @@ Perl_yylex(pTHX)
8cee2a9
 		SAVEI32(PL_lex_formbrack);
8cee2a9
 		PL_parser->form_lex_state = PL_lex_state;
8cee2a9
 		PL_lex_formbrack = PL_lex_brackets + 1;
8cee2a9
+                PL_parser->sub_error_count = PL_error_count;
8cee2a9
 		goto leftbracket;
8cee2a9
 	    }
8cee2a9
 	}
8cee2a9
-- 
8cee2a9
2.17.2
8cee2a9