Avoid die while decoding erroneus json data

This commit is contained in:
fbsanchez 2021-05-07 14:15:16 +02:00
parent 454e6120e4
commit d160737fb2

View File

@ -2462,6 +2462,8 @@ sub p_decode_json {
my ($pa_config, $data) = @_; my ($pa_config, $data) = @_;
my $decoded_data; my $decoded_data;
eval {
local $SIG{__DIE__};
if ($JSON::VERSION > 2.90) { if ($JSON::VERSION > 2.90) {
# Initialize JSON manager. # Initialize JSON manager.
my $json = JSON->new->utf8->allow_nonref; my $json = JSON->new->utf8->allow_nonref;
@ -2469,6 +2471,12 @@ sub p_decode_json {
} else { } else {
$decoded_data = decode_json($data); $decoded_data = decode_json($data);
} }
};
if ($@){
if (defined($data)) {
logger($pa_config, 'Failed to decode data: '.$@, 5);
}
}
return $decoded_data; return $decoded_data;
} }