From 65062e29ae04fc31a47b053025b4b1aa22b6f4b7 Mon Sep 17 00:00:00 2001 From: Vincent Pit Date: Wed, 9 Sep 2009 21:04:11 +0200 Subject: [PATCH] Don't let pp_entersub overwrite the stack with the elements of @_ --- TryCatch.xs | 8 +++++++- t/method.t | 21 +++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 t/method.t diff --git a/TryCatch.xs b/TryCatch.xs index 96f14ac..06a8f96 100644 --- a/TryCatch.xs +++ b/TryCatch.xs @@ -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); } diff --git a/t/method.t b/t/method.t new file mode 100644 index 0000000..d12d229 --- /dev/null +++ b/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");