safe-module and namespaces

P

peter pilsl

I try to use the safe-module to evaluate user-provided code, but it
seems there is a knot in my brain.

use Safe;
$s=new Safe "xxx";
$xxx::x=3;
$s->reval('$x=4');
print $xxx::x,"\n"


Well, this prints out 3 as result and I think it should be 4!
What am I not thinking of?

thnx,
peter
 
B

Brian McCauley

peter said:
I try to use the safe-module to evaluate user-provided code, but it
seems there is a knot in my brain.

use Safe;
$s=new Safe "xxx";
$xxx::x=3;
$s->reval('$x=4');
print $xxx::x,"\n"


Well, this prints out 3 as result and I think it should be 4!

Works OK for me (i.e. prints 4) with Perl 5.8.7 and Safe 2.11
 
C

Charles DeRykus

peter said:
I try to use the safe-module to evaluate user-provided code, but it
seems there is a knot in my brain.

use Safe;
$s=new Safe "xxx";
$xxx::x=3;
$s->reval('$x=4');
print $xxx::x,"\n"


Well, this prints out 3 as result and I think it should be 4!
What am I not thinking of?

I don't know Safe well... ok, hardly at all.

But, I suspect package variables seen outside the safe
compartment are no longer accessible. I'm not sure how
the mechanism works to ensure that.

If 'xxx' is explicitly shared, the following does print '4'.

my $s = Safe->new( "xxx" );
$xxx::x=3;
$s->share_from('xxx', ['$x'] );
$s->reval('$x=4');
print $xxx::x;
 
C

Charles DeRykus

Brian said:
Works OK for me (i.e. prints 4) with Perl 5.8.7 and Safe 2.11

Odd, I could've sworn I duplicated Peter's results but I confirmed
it works on 5.6.1 and Safe 2.06 as well as 5.8.8 and Safe 2.12 too.

So, forget my earlier suggestion to explicitly share 'xxx'...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
474,189
Messages
2,571,016
Members
47,616
Latest member
gijoji4272

Latest Threads

Top