From a19b2614dc94a48a58f6af1176a43d56a1a636f3 Mon Sep 17 00:00:00 2001 From: Neil Lathwood Date: Fri, 3 Feb 2017 14:12:42 +0000 Subject: [PATCH] fix: added some timeout safeguards for curl calls (#5743) --- includes/common.php | 3 +++ includes/functions.php | 1 + includes/polling/functions.inc.php | 3 +++ 3 files changed, 7 insertions(+) diff --git a/includes/common.php b/includes/common.php index 5497657a65..bc782c93e8 100644 --- a/includes/common.php +++ b/includes/common.php @@ -1093,6 +1093,9 @@ function version_info($remote = true) curl_setopt($api, CURLOPT_USERAGENT, 'LibreNMS'); curl_setopt($api, CURLOPT_URL, $config['github_api'].'commits/master'); curl_setopt($api, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($api, CURLOPT_TIMEOUT, 5); + curl_setopt($api, CURLOPT_TIMEOUT_MS, 5000); + curl_setopt($api, CURLOPT_CONNECTTIMEOUT, 5); $output['github'] = json_decode(curl_exec($api), true); } list($local_sha, $local_date) = explode('|', rtrim(`git show --pretty='%H|%ct' -s HEAD`)); diff --git a/includes/functions.php b/includes/functions.php index 2194139de1..75c25a3573 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -1499,6 +1499,7 @@ function oxidized_reload_nodes() $ch = curl_init($oxidized_reload_url); curl_setopt($ch, CURLOPT_TIMEOUT, 5); + curl_setopt($ch, CURLOPT_TIMEOUT_MS, 5000); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, 1); diff --git a/includes/polling/functions.inc.php b/includes/polling/functions.inc.php index c83af550f0..6c7e9cd8ac 100644 --- a/includes/polling/functions.inc.php +++ b/includes/polling/functions.inc.php @@ -513,6 +513,9 @@ function location_to_latlng($device) $curl_init = curl_init($api_url); set_curl_proxy($curl_init); curl_setopt($curl_init, CURLOPT_RETURNTRANSFER, true); + curl_setopt($curl_init, CURLOPT_TIMEOUT, 2); + curl_setopt($curl_init, CURLOPT_TIMEOUT_MS, 2000); + curl_setopt($curl_init, CURLOPT_CONNECTTIMEOUT, 5); $data = json_decode(curl_exec($curl_init), true); // Parse the data from the specific Geocode services. switch ($config['geoloc']['engine']) {