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 /t/op | |
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 't/op')
-rw-r--r-- | t/op/heredoc.t | 12 | ||||
-rw-r--r-- | t/op/lex.t | 4 | ||||
-rw-r--r-- | t/op/sub.t | 9 | ||||
-rw-r--r-- | t/op/tie.t | 8 |
4 files changed, 25 insertions, 8 deletions
diff --git a/t/op/heredoc.t b/t/op/heredoc.t index 0a7bb06b0f..6e7e895def 100644 --- a/t/op/heredoc.t +++ b/t/op/heredoc.t @@ -7,7 +7,7 @@ BEGIN { } use strict; -plan(tests => 137); +plan(tests => 138); # heredoc without newline (#65838) { @@ -233,3 +233,13 @@ HEREDOC ); } } +fresh_perl_like( +q#<<E1; +${sub{b{]]]{} @{[ <<E2 ]} +E2 +E1 +#, + qr/^syntax error/, + {}, + "GH Issue #17397 - Syntax error inside of here doc causes segfault" +); diff --git a/t/op/lex.t b/t/op/lex.t index 59be493768..11a056af2e 100644 --- a/t/op/lex.t +++ b/t/op/lex.t @@ -134,7 +134,7 @@ SKIP: { Bareword found where operator expected at - line 1, near ""ab}"ax" (Missing operator before ax?) syntax error at - line 1, near ""ab}"ax" -Unrecognized character \\x8A; marked by <-- HERE after ab}"ax;&\0z<-- HERE near column 12 at - line 1. +Execution of - aborted due to compilation errors. gibberish { stderr => 1 }, 'gibberish containing &\0z - used to crash [perl #123753]' @@ -144,7 +144,7 @@ gibberish Bareword found where operator expected at - line 1, near ""ab}"ax" (Missing operator before ax?) syntax error at - line 1, near ""ab}"ax" -Unrecognized character \\x8A; marked by <-- HERE after }"ax;&{+z}<-- HERE near column 14 at - line 1. +Execution of - aborted due to compilation errors. gibberish { stderr => 1 }, 'gibberish containing &{+z} - used to crash [perl #123753]' diff --git a/t/op/sub.t b/t/op/sub.t index 11d7147e5d..09f5609b49 100644 --- a/t/op/sub.t +++ b/t/op/sub.t @@ -6,7 +6,7 @@ BEGIN { set_up_inc('../lib'); } -plan(tests => 62); +plan(tests => 63); sub empty_sub {} @@ -426,3 +426,10 @@ eval ' CORE::state sub b; sub d { sub b {} sub d } '; eval '()=%e; sub e { sub e; eval q|$x| } e;'; + +fresh_perl_like( + q#<s,,$0[sub{m]]]],}>0,shift#, + qr/^syntax error/, + {}, + "GH Issue #16944 - Syntax error with sub and shift causes segfault" +); diff --git a/t/op/tie.t b/t/op/tie.t index 9cc1599331..673ec49dce 100644 --- a/t/op/tie.t +++ b/t/op/tie.t @@ -731,10 +731,10 @@ $foo{'exit'}; print "overshot main\n"; # shouldn't reach here EXPECT -eval: s0=EVAL-BD-BS-E1-S1-E2-S2-S2-S2-S2-S2-S2-S2-S2-S2-S2-R -eval: s1=EVAL-BD-BS-E1-S1-E2-S2-S2-S2-S2-S2-S2-S2-S2-S2-S2-R -eval: s2=EVAL-BD-BS-E1-S1-E2-S2-S2-S2-S2-S2-S2-S2-S2-S2-S2-R -eval: s3=EVAL-BD-BS-E1-S1-E2-S2-S2-S2-S2-S2-S2-S2-S2-S2-S2-R +eval: s0=EVAL-BD-BS-E1-S1-E2-S2-R +eval: s1=EVAL-BD-BS-E1-S1-E2-S2-R +eval: s2=EVAL-BD-BS-E1-S1-E2-S2-R +eval: s3=EVAL-BD-BS-E1-S1-E2-S2-R require: s0=REQUIRE-0-ERQ-ENDRQ-1-ERQ-ENDRQ-2-ERQ-ENDRQ-3-ERQ-ENDRQ-R require: s1=REQUIRE-0-RQ require: s2=REQUIRE-0-ERQ-ENDRQ-1-ERQ-ENDRQ-2-ERQ-ENDRQ-3-ERQ-ENDRQ-R |