3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-26 22:09:26 +01:00

Factoids: remove execute_code_factoid_using_safe

This commit is contained in:
Pragmatic Software 2019-06-02 19:31:25 -07:00
parent bb08250673
commit 5eeabccaf2
2 changed files with 0 additions and 101 deletions

View File

@ -141,11 +141,4 @@ sub interpreter {
return undef;
}
sub parse_arguments {
my ($self, $arguments) = @_;
my $args = quotemeta $arguments;
$args =~ s/\\ / /g;
return shellwords($args);
}
1;

View File

@ -655,100 +655,6 @@ sub expand_action_arguments {
return $action;
}
sub execute_code_factoid_using_safe {
my ($self, $nick, $user, $host, $from, $chan, $root_keyword, $keyword, $arguments, $lang, $code, $tonick) = @_;
return "/say code-factoids are temporarily disabled.";
my $ppi = PPI::Document->new(\$code, readonly => 1);
return "/say $nick: I don't feel so good." if not $ppi;
my $vars = $ppi->find(sub { $_[1]->isa('PPI::Token::Symbol') });
my @names = map { $_->symbol =~ /^[\%\@\$]+(.*)/; $1 } @$vars if $vars;
my %uniq = map { $_, 1 } @names;
@names = keys %uniq;
unless ($self->{factoids}->hash->{$chan}->{$keyword}->{interpolate} eq '0') {
$code = $self->expand_factoid_vars($from, $nick, $root_keyword, $code, @names);
}
my %signals = %SIG;
alarm 0;
my $safe;
my $new_compartment;
if ($self->{factoids}->hash->{$chan}->{$keyword}->{'persist-key'}) {
my $key = $self->{factoids}->hash->{$chan}->{$keyword}->{'persist-key'};
if ($self->{compartments}->{$key}) {
$safe = $self->{compartments}->{$key};
} else {
$new_compartment = $key;
}
}
if (not defined $safe) {
$safe = Safe->new;
$safe->permit_only(qw/:base_core rv2gv padany rand srand concat subst join sort mapstart grepstart/);
$safe->deny(qw/entersub/);
# some default stuff
$safe->reval('$" = " ";');
$self->{compartments}->{$new_compartment} = $safe if $new_compartment;
}
no warnings;
local our @args = $self->{pbot}->{commands}->parse_arguments($arguments);
local our $nick = $nick;
local our $channel = $from;
use warnings;
@args = ($nick) if not @args;
$arguments = '';
$safe->share(qw/@args $nick $channel/);
my $action = eval {
$self->{pbot}->{logger}->log("evaling [$code]\n");
my $result = $safe->reval($code);
if ($@) {
my $error = $@;
chomp $error;
$error =~ s/trapped by operation.*/operation disallowed (we're still fine-tuning this; let us know if you think this should be allowed)/;
$error =~ s/at \(eval \d+\) line 1.//g;
$error = "$error (did you forget to use quotes around factoid variables?)" if $error =~ /syntax error/;
return "/say Error in factoid code: $error";
} else {
return $result;
}
};
if ($@) {
my $error = $@;
chomp $error;
$error =~ s/at \(eval \d+\) line 1.//g;
$action = "/say Error in factoid: $error";
}
%SIG = %signals;
alarm 1;
unless ($self->{factoids}->hash->{$chan}->{$keyword}->{interpolate} eq '0') {
$action = $self->expand_factoid_vars($from, $nick, $root_keyword, $action);
if ($self->{factoids}->hash->{$chan}->{$keyword}->{'allow_empty_args'}) {
$action = $self->expand_action_arguments($action, $arguments, '');
} else {
$action = $self->expand_action_arguments($action, $arguments, $nick);
}
} else {
$action = validate_string($action, $self->{pbot}->{registry}->get_value('factoids', 'max_content_length'));
}
return $action;
}
sub execute_code_factoid_using_vm {
my ($self, $stuff) = @_;