develooper Front page | perl.perl5.porters | Postings from May 2004

[PATCH] Re: [perl #29851] Problem with Carp and Safe

Thread Previous | Thread Next
From:
Rafael Garcia-Suarez
Date:
May 31, 2004 06:31
Subject:
[PATCH] Re: [perl #29851] Problem with Carp and Safe
Message ID:
20040531152854.79fd0a3b@localhost
Dave Mitchell wrote:
> > After debugging, the problem seems to be in some incompatibility
> > between Carp and Safe.
...
> Carp will sometimes do:
> 
>     { local $@; require Carp::Heavy; }
> 
> Since require isn't allowed within the compartment, Perl raises an exception;
> control is unwound to the eval done by the Safe::reval, then all the saved
> stuff like the local()s are unwound, thus blowing away the error message
> in $@.

Given that require is a dangerous op, that Safe compartments surely want
to block, I suggest a two-phase fix :

* require Carp::Heavy in the user code, before executing the Safe
  compartment
* use the following patch to skip the unneeded require():

Index: lib/Carp.pm
===================================================================
--- lib/Carp.pm	(revision 3553)
+++ lib/Carp.pm	(working copy)
@@ -155,7 +155,11 @@
 # each function call on the stack.
 
 sub longmess {
-    { local $@; require Carp::Heavy; }	# XXX fix require to not clear $@?
+    {
+	local $@;
+	# XXX fix require to not clear $@?
+	require Carp::Heavy unless $INC{"Carp/Heavy.pm"};
+    }
     # Icky backwards compatibility wrapper. :-(
     my $call_pack = caller();
     if ($Internal{$call_pack} or $CarpInternal{$call_pack}) {
@@ -175,7 +179,11 @@
 # you always get a stack trace
 
 sub shortmess {	# Short-circuit &longmess if called via multiple packages
-    { local $@; require Carp::Heavy; }	# XXX fix require to not clear $@?
+    {
+	local $@;
+	# XXX fix require to not clear $@?
+	require Carp::Heavy unless $INC{"Carp/Heavy.pm"};
+    }
     # Icky backwards compatibility wrapper. :-(
     my $call_pack = caller();
     local @CARP_NOT = caller();

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About