Skip to content

Commit

Permalink
* Solve several problems that related to PerlAlwaysGlobal taking over…
Browse files Browse the repository at this point in the history
… for

  former use of [perl tables="something"].

* When in PerlAlwaysGlobal mode, DO NOT wrap database objects with Safe. No point, and
  all that happens is you expose yourself to Encode and other modules erroring out
  when runtime requires are done.

* Likewise, do not use the wrapped $Tag, just make a new Vend::Tags object.

* Also, in global mode the non-lexical variables created in [perl] tags
  could not be accessed in [calc] or `backtick code` in tag parameters.
  Used the Safe root() function to set the package for [perl] tags
  when in PerlAlwaysGlobal mode. Did not do this when PerlAlwaysGlobal
  not set, as existing global Perl users could conceivably be affected.
  • Loading branch information
Mike Heins committed Jan 31, 2017
1 parent a8195b2 commit 81d1395
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions lib/Vend/Interpolate.pm
Expand Up @@ -1612,6 +1612,19 @@ sub tag_perl {
}
}

$MVSAFE::Safe = 1;
my $always_global = $Global::PerlAlwaysGlobal->{$Vend::Cat};
my $not_global = 1;
if (
( $opt->{global} or (! defined $opt->{global} and $always_global ) )
and
$Global::AllowGlobal->{$Vend::Cat}
)
{
$MVSAFE::Safe = 0 unless $MVSAFE::Unsafe;
$not_global = 0;
}

if($tables) {
my (@tab) = grep /\S/, split /\s+/, $tables;
foreach my $tab (@tab) {
Expand All @@ -1628,7 +1641,7 @@ sub tag_perl {
$dbh = $db->dbh();
}

if($hole) {
if($not_global and $hole) {
if ($dbh) {
$Sql{$tab} = $hole->wrap($dbh);
}
Expand All @@ -1645,7 +1658,14 @@ sub tag_perl {
}
}

$Tag = $hole->wrap($Tag) if $hole and ! $Vend::TagWrapped++;
if($not_global) {
$Vend::TagWrapped ||= $Tag = $hole->wrap($Tag);
}
else {
$Tag = new Vend::Tags;
}

Debug("Not global? not_global=$not_global Tag=$Tag Db=$Db{userdb} MVSAFE::Safe=$MVSAFE::Safe");

init_calc() if ! $Vend::Calc_initialized;
$ready_safe->share(@share) if @share;
Expand All @@ -1670,14 +1690,10 @@ sub tag_perl {

$body =~ tr/\r//d if $Global::Windows;

$MVSAFE::Safe = 1;
if (
( $opt->{global} or (! defined $opt->{global} and $Global::PerlAlwaysGlobal->{$Vend::Cat} ) )
and
$Global::AllowGlobal->{$Vend::Cat}
)
{
$MVSAFE::Safe = 0 unless $MVSAFE::Unsafe;
### Make calc/perl namespaces match
if($always_global) {
my $safepackage = $ready_safe->root();
$body = "package $safepackage;\n$body";
}

if(! $MVSAFE::Safe) {
Expand All @@ -1693,6 +1709,8 @@ sub tag_perl {
$result = $ready_safe->reval($body);
}

## Package might have changed with PerlAlwaysGlobal
package Vend::Interpolate;
undef $MVSAFE::Safe;

if ($@) {
Expand Down

0 comments on commit 81d1395

Please sign in to comment.