summaryrefslogtreecommitdiff
path: root/pod/perlfunc.pod
diff options
context:
space:
mode:
authorYves Orton <demerphq@gmail.com>2022-08-28 12:09:51 +0200
committerYves Orton <demerphq@gmail.com>2022-09-02 10:05:42 +0200
commit741a5c7396a0ca90a22ea8d8e0761c70c14b0a77 (patch)
tree0c442705b8ff90ebda90515e6c601ab6784af8fb /pod/perlfunc.pod
parentcd55125d69f5f698ef7cbdd650cda7d2e59fc388 (diff)
downloadperl-741a5c7396a0ca90a22ea8d8e0761c70c14b0a77.tar.gz
op.c - Restrict nested eval/BEGIN blocks to a user controllable maximum
Nested BEGIN blocks can cause us to segfault by exhausting the C stack. Eg: perl -le'sub f { eval "BEGIN { f() }" } f()' will segfault. This adds a new interpreter var PL_eval_begin_nest_depth to keep track of how many layer of eval/BEGIN we have seen, and a new reserved variable called ${^MAX_NESTED_EVAL_BEGIN_BLOCKS} which can be used to raise or lower the limit. When set to 0 it blocks BEGIN entirely, which might be useful from time to time. This fixes https://github.com/Perl/perl5/issues/20176
Diffstat (limited to 'pod/perlfunc.pod')
-rw-r--r--pod/perlfunc.pod10
1 files changed, 10 insertions, 0 deletions
diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod
index fa16cbd69c..b723cbbcb1 100644
--- a/pod/perlfunc.pod
+++ b/pod/perlfunc.pod
@@ -2237,6 +2237,16 @@ context of the current Perl program, any outer lexical variables are
visible to it, and any package variable settings or subroutine and
format definitions remain afterwards.
+Note that when C<BEGIN {}> blocks are embedded inside of an eval block
+the contents of the block will be executed immediately and before the rest
+of the eval code is executed. You can disable this entirely by
+
+ local ${^MAX_NESTED_EVAL_BEGIN_BLOCKS} = 0;
+ eval $string;
+
+which will cause any embedded C<BEGIN> blocks in C<$string> to throw an
+exception.
+
=over 4
=item Under the L<C<"unicode_eval"> feature|feature/The 'unicode_eval' and 'evalbytes' features>