FAQ
S_vdie_common has very similar code to Perl_vwarn. Should the change to re-
zero PL_warnhook also be made to the analogous position in S_vdie_common?
I don't seem to be able to take the warn example code and convert it to a
die version that misbehaves.

Nicholas Clark

Change 25160 by davem@davem-splatty on 2005/07/17 20:12:54

$SIG{__WARN__} = sub { goto &foo } could recurse infinitely

Affected files ...

... //depot/perl/t/op/goto.t#30 edit
... //depot/perl/util.c#484 edit

Differences ...

==== //depot/perl/t/op/goto.t#30 (xtext) ====

@@ -10,7 +10,7 @@

use warnings;
use strict;
-plan tests => 56;
+plan tests => 57;

our $foo;
while ($?) {
@@ -436,3 +436,13 @@
like($@, qr/Can't goto subroutine from an eval-string/, 'eval string');
eval { goto &null };
like($@, qr/Can't goto subroutine from an eval-block/, 'eval block');
+
+# [perl #36521] goto &foo in warn handler could defeat recursion avoider
+
+{
+ my $r = runperl(
+ stderr => 1,
+ prog => 'my $d; my $w = sub { return if $d++; warn q(bar)}; local $SIG{__WARN__} = sub { goto &$w; }; warn q(foo);'
+ );
+ like($r, qr/bar/, "goto &foo in warn");
+}

==== //depot/perl/util.c#484 (text) ====

@@ -1278,6 +1278,8 @@
SV *msg;

ENTER;
+ SAVESPTR(PL_warnhook);
+ PL_warnhook = Nullsv;
save_re_context();
msg = newSVpvn(message, msglen);
SvFLAGS(msg) |= utf8;

Search Discussions

  • Dave Mitchell at Jan 4, 2006 at 8:10 pm

    On Mon, Dec 26, 2005 at 01:59:30PM +0000, Nicholas Clark wrote:
    S_vdie_common has very similar code to Perl_vwarn. Should the change to re-
    zero PL_warnhook also be made to the analogous position in S_vdie_common?
    I don't seem to be able to take the warn example code and convert it to a
    die version that misbehaves.
    From perlvar:

    The routine indicated by C<$SIG{__DIE__}> is called when a fatal
    exception is about to be thrown. The error message is passed as the
    first argument. When a __DIE__ hook routine returns, the exception
    processing continues as it would have in the absence of the hook,
    unless the hook routine itself exits via a C<goto>, a loop exit, or a
    ^^^^
    die().
    ^^^^^

    Since a die within $SIG{__DIE__} is explicitly documented, I presume that
    perl can cope with it, unlike the __WARN__ case. That probably explains
    why you couldn't get a die misbehaving case. Not that I've actually looked
    at the code in S_vdie_common to confirm.
    Nicholas Clark

    Change 25160 by davem@davem-splatty on 2005/07/17 20:12:54

    $SIG{__WARN__} = sub { goto &foo } could recurse infinitely

    Affected files ...

    ... //depot/perl/t/op/goto.t#30 edit
    ... //depot/perl/util.c#484 edit

    Differences ...

    ==== //depot/perl/t/op/goto.t#30 (xtext) ====

    @@ -10,7 +10,7 @@

    use warnings;
    use strict;
    -plan tests => 56;
    +plan tests => 57;

    our $foo;
    while ($?) {
    @@ -436,3 +436,13 @@
    like($@, qr/Can't goto subroutine from an eval-string/, 'eval string');
    eval { goto &null };
    like($@, qr/Can't goto subroutine from an eval-block/, 'eval block');
    +
    +# [perl #36521] goto &foo in warn handler could defeat recursion avoider
    +
    +{
    + my $r = runperl(
    + stderr => 1,
    + prog => 'my $d; my $w = sub { return if $d++; warn q(bar)}; local $SIG{__WARN__} = sub { goto &$w; }; warn q(foo);'
    + );
    + like($r, qr/bar/, "goto &foo in warn");
    +}

    ==== //depot/perl/util.c#484 (text) ====

    @@ -1278,6 +1278,8 @@
    SV *msg;

    ENTER;
    + SAVESPTR(PL_warnhook);
    + PL_warnhook = Nullsv;
    save_re_context();
    msg = newSVpvn(message, msglen);
    SvFLAGS(msg) |= utf8;
    --
    "Foul and greedy Dwarf - you have eaten the last candle."
    -- "Hordes of the Things", BBC Radio.
  • Nicholas Clark at Jan 12, 2006 at 4:08 pm

    On Wed, Jan 04, 2006 at 08:12:15PM +0000, Dave Mitchell wrote:
    On Mon, Dec 26, 2005 at 01:59:30PM +0000, Nicholas Clark wrote:
    S_vdie_common has very similar code to Perl_vwarn. Should the change to re-
    zero PL_warnhook also be made to the analogous position in S_vdie_common?
    I don't seem to be able to take the warn example code and convert it to a
    die version that misbehaves.
    From perlvar:
    The routine indicated by C<$SIG{__DIE__}> is called when a fatal
    exception is about to be thrown. The error message is passed as the
    first argument. When a __DIE__ hook routine returns, the exception
    processing continues as it would have in the absence of the hook,
    unless the hook routine itself exits via a C<goto>, a loop exit, or a
    ^^^^
    die().
    ^^^^^

    Since a die within $SIG{__DIE__} is explicitly documented, I presume that
    perl can cope with it, unlike the __WARN__ case. That probably explains
    why you couldn't get a die misbehaving case. Not that I've actually looked
    at the code in S_vdie_common to confirm.
    Thanks.

    This related to what became change 26787 (Refactor S_vdie_common so that
    Perl_vwarn can use it too.). It seemed to save .7K of object code size.

    Nicholas Clark

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupperl5-porters @
categoriesperl
postedDec 26, '05 at 1:59p
activeJan 12, '06 at 4:08p
posts3
users2
websiteperl.org

2 users in discussion

Nicholas Clark: 2 posts Dave Mitchell: 1 post

People

Translate

site design / logo © 2022 Grokbase