From 75efa9df6f76416b9a0971398308824fad5e4a0c Mon Sep 17 00:00:00 2001 From: jsatoh Date: Thu, 8 May 2014 05:12:08 +0000 Subject: [PATCH] 2014-05-08 Junichi Satoh * lib/PandoraFMS/ReconServer.pm: Fixed crash when macros help of recon script contains \r, \n or multibyte characters. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@9886 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_server/ChangeLog | 5 +++++ pandora_server/lib/PandoraFMS/ReconServer.pm | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index ee3e4306f5..4eee1931ea 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,8 @@ +2014-05-08 Junichi Satoh + + * lib/PandoraFMS/ReconServer.pm: Fixed crash when macros help of + recon script contains \r, \n or multibyte characters. + 2014-05-07 Ramon Novoa * lib/PandoraFMS/Tools.pm: Added code to initialize the enterprise module. diff --git a/pandora_server/lib/PandoraFMS/ReconServer.pm b/pandora_server/lib/PandoraFMS/ReconServer.pm index 1ed76f0ee1..3f94724999 100644 --- a/pandora_server/lib/PandoraFMS/ReconServer.pm +++ b/pandora_server/lib/PandoraFMS/ReconServer.pm @@ -27,6 +27,7 @@ use Thread::Semaphore; use IO::Socket::INET; use POSIX qw(strftime ceil); use JSON qw(decode_json encode_json); +use Encode qw(encode_utf8); # Default lib dir for RPM and DEB packages use lib '/usr/lib/perl5'; @@ -484,7 +485,11 @@ sub exec_recon_script ($$$) { my $command = safe_output($script->{'script'}); my $macros = safe_output($task->{'macros'}); - my $decoded_macros = decode_json ($macros); + + # \r and \n should be escaped for decode_json(). + $macros =~ s/\n/\\n/g; + $macros =~ s/\r/\\r/g; + my $decoded_macros = decode_json (encode_utf8($macros)); my $macros_parameters = '';