From 6c506e9dd0602d08a9750e98ea994bafcd6e5d82 Mon Sep 17 00:00:00 2001 From: Ramon Novoa Date: Thu, 22 Sep 2022 17:04:43 +0200 Subject: [PATCH] Improved error detection when calling curl. Ref. pandora_enterprise#8359. --- pandora_server/lib/PandoraFMS/Goliat/GoliatCURL.pm | 3 +++ pandora_server/lib/PandoraFMS/Goliat/GoliatLWP.pm | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/pandora_server/lib/PandoraFMS/Goliat/GoliatCURL.pm b/pandora_server/lib/PandoraFMS/Goliat/GoliatCURL.pm index 63fe5ca5de..9fdd4cfee0 100755 --- a/pandora_server/lib/PandoraFMS/Goliat/GoliatCURL.pm +++ b/pandora_server/lib/PandoraFMS/Goliat/GoliatCURL.pm @@ -336,6 +336,9 @@ sub curl { my $cmd = "curl $curl_opts " . safe_param($url); my $response = `"$exec" $timeout $cmd 2>/dev/null`; + if ($? == -1) { + die("Error calling curl. Not enough memory?\n"); + } # Curl command stored for live debugging feature. set_update_agentmodule ($dbh, $moduleId, { 'debug_content' => $cmd }) if defined($dbh); diff --git a/pandora_server/lib/PandoraFMS/Goliat/GoliatLWP.pm b/pandora_server/lib/PandoraFMS/Goliat/GoliatLWP.pm index 65e22c5f1e..d22c0e5c6a 100755 --- a/pandora_server/lib/PandoraFMS/Goliat/GoliatLWP.pm +++ b/pandora_server/lib/PandoraFMS/Goliat/GoliatLWP.pm @@ -110,6 +110,9 @@ sub g_http_task { my $get_content_advanced = ""; my $ua = new LWP::UserAgent; + if (!defined($ua)) { + die("LWP::UserAgent->new() failed. Not enough memory?"); + } $task_requests [$thread_id] = 0 ; $task_sessions [$thread_id] = 0 ; $task_reqsec[$thread_id] = 0; @@ -388,6 +391,9 @@ sub g_get_page { my $debug = $_[3]; my $req = HTTP::Request->new(GET => $url); + if (!defined($req)) { + die("HTTP::Request->new() failed. Not enough memory?"); + } $req->header('Accept' => 'text/html'); while (my ($header, $value) = each %{$headers}) { $req->header($header => $value); @@ -418,6 +424,9 @@ sub g_head_page { my $debug = $_[3]; my $req = HTTP::Request->new(HEAD => $url); + if (!defined($req)) { + die("HTTP::Request->new() failed. Not enough memory?"); + } $req->header('Accept' => 'text/html'); while (my ($header, $value) = each %{$headers}) { $req->header($header => $value);