Skip to content

Commit

Permalink
Don't let pp_entersub overwrite the stack with the elements of @_
Browse files Browse the repository at this point in the history
  • Loading branch information
vpit authored and ashb committed Sep 9, 2009
1 parent 43bffc3 commit 65062e2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
8 changes: 7 additions & 1 deletion TryCatch.xs
Expand Up @@ -88,7 +88,13 @@ STATIC OP* unwind_return (pTHX_ OP *op, void *user_data) {
XPUSHs( (SV*)unwind);
PUTBACK;

return CALL_FPTR(PL_ppaddr[OP_ENTERSUB])(aTHXR);
/* pp_entersub gets the XSUB arguments from @_ if there are any.
* Bypass this as we pushed the arguments directly on the stack. */

if (CvISXSUB(unwind))
AvFILLp(GvAV(PL_defgv)) = -1;

return CALL_FPTR(PL_ppaddr[OP_ENTERSUB])(aTHX);
}


Expand Down
21 changes: 21 additions & 0 deletions t/method.t
@@ -0,0 +1,21 @@
#!perl

use Test::More tests => 3;

use strict;
use warnings;

use TryCatch;

sub content {
try {
return "pass";
} catch ($e) {
return "'an error occurred'";
}
return "fail";
}

is (main::content(), "pass", "function");
is (main->content(), "pass", "class method");
is ((bless {})->content(), "pass", "instance method");

0 comments on commit 65062e2

Please sign in to comment.