revert security - patch in progress

This commit is contained in:
garnier-quentin 2021-03-30 16:37:19 +02:00
parent 68b743b720
commit 68c0bead7d
2 changed files with 4 additions and 25 deletions

View File

@ -26,7 +26,6 @@ use strict;
use warnings;
use JSON::XS;
use centreon::plugins::statefile;
use Safe;
sub custom_select_threshold {
my ($self, %options) = @_;
@ -38,13 +37,13 @@ sub custom_select_threshold {
local $SIG{__DIE__} = sub { $message = $_[0]; };
if (defined($self->{result_values}->{config}->{critical}) && $self->{result_values}->{config}->{critical} &&
$self->{instance_mode}->{safe}->reval($self->{result_values}->{config}->{critical})) {
eval "$self->{result_values}->{config}->{critical}") {
$status = 'critical';
} elsif (defined($self->{result_values}->{config}->{warning}) && $self->{result_values}->{config}->{warning} ne '' &&
$self->{instance_mode}->{safe}->reval($self->{result_values}->{config}->{warning})) {
eval "$self->{result_values}->{config}->{warning}") {
$status = 'warning';
} elsif (defined($self->{result_values}->{config}->{unknown}) && $self->{result_values}->{config}->{unknown} &&
$self->{instance_mode}->{safe}->reval($self->{result_values}->{config}->{unknown})) {
eval "$self->{result_values}->{config}->{unknown}") {
$status = 'unknown';
}
if ($@) {
@ -129,7 +128,6 @@ sub new {
'filter-selection:s%' => { name => 'filter_selection' },
});
$self->{safe} = Safe->new();
$self->{snmp_cache} = centreon::plugins::statefile->new(%options);
return $self;
}
@ -743,12 +741,7 @@ sub check_filter {
return 0 if (!defined($options{filter}) || $options{filter} eq '');
$options{filter} =~ s/%\(([a-z-A-Z0-9\.]+?)\)/\$self->{expand}->{'$1'}/g;
my $result = $self->{safe}->reval("$options{filter}");
if ($@) {
$self->{output}->add_option_msg(short_msg => 'Unsafe code evaluation: ' . $@);
$self->{output}->option_exit();
}
return 0 if ($result);
return 0 if (eval "$options{filter}");
return 1;
}

View File

@ -753,23 +753,9 @@ sub compat_threshold_counter {
sub change_macros {
my ($self, %options) = @_;
my ($code) = centreon::plugins::misc::mymodule_load(
output => $self->{output}, module => 'Safe',
no_quit => 1
);
my $safe;
$safe = Safe->new() if ($code == 0);
foreach (@{$options{macros}}) {
if (defined($self->{option_results}->{$_}) && $self->{option_results}->{$_} ne '') {
$self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g;
if ($code == 0) {
my $result = $safe->reval($self->{option_results}->{$_});
if ($@) {
$self->{output}->add_option_msg(short_msg => 'Unsafe code evaluation: ' . $@);
$self->{output}->option_exit();
}
}
}
}
}