-
Notifications
You must be signed in to change notification settings - Fork 17
OPSLAB-245: Enhance error management in stormshield #334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,9 @@ | |
| require_once 'smsd/sms_common.php'; | ||
| require_once 'smsd/expect.php'; | ||
| require_once 'smsd/generic_connection.php'; | ||
|
|
||
| require_once load_once('stormshield', 'nsrpc.php'); | ||
|
|
||
| require_once "$db_objects"; | ||
|
|
||
| class connect extends GenericConnection { | ||
|
|
@@ -21,6 +24,7 @@ class connect extends GenericConnection { | |
| private $response; | ||
| private $cookie; | ||
| private $session_id; | ||
| private $curl_cmd; | ||
|
|
||
| public function __construct($ip = null, $login = null, $passwd = null, $admin_password = null, $port = null) | ||
| { | ||
|
|
@@ -117,15 +121,6 @@ public function send($origin, $rest_cmd) { | |
|
|
||
| $url = "https://{$this->sd_ip_config}/{$rest_path}"; | ||
|
|
||
| $headers = ''; | ||
| foreach ($this->http_header_list as $header) { | ||
| $H = trim($header); | ||
| $headers .= " -H '{$H}'"; | ||
| } | ||
|
|
||
| // for debug | ||
| $curl_cmd = "curl -X {$http_op} {$headers} --connect-timeout {$this->conn_timeout} --max-time {$this->conn_timeout} -k '{$url}'"; | ||
|
|
||
| if (count($cmd_list) > 2) { | ||
| if (isset($this->session_id)) { | ||
| $payload = $cmd_list[2]; | ||
|
|
@@ -157,14 +152,25 @@ public function send($origin, $rest_cmd) { | |
| $rest_payload = ''; | ||
| } | ||
|
|
||
| $curl_cmd .= " --data-raw '{$rest_payload}'"; | ||
| $this->execute_curl_command($origin, $http_op, $url, $rest_payload); | ||
|
|
||
| debug_dump($curl_cmd, "HTTP REQUEST:\n"); | ||
| $this->execute_curl_command($origin, $http_op, $url, $rest_payload, $curl_cmd); | ||
| debug_dump($this->response, "HTTP RESPONSE:\n"); | ||
| $ret = is_error_xml($this->response); | ||
| if ($ret !== false) | ||
| { | ||
| throw new SmsException("Response to API {$this->curl_cmd} Failed: \n$ret", ERR_SD_CMDFAILED, $origin); | ||
| } | ||
| } | ||
|
|
||
| private function execute_curl_command($origin, $http_op, $url, $rest_payload, $curl_cmd) { | ||
| private function execute_curl_command($origin, $http_op, $url, $rest_payload) { | ||
|
|
||
| // for debug | ||
| $headers = ''; | ||
| foreach ($this->http_header_list as $h) { | ||
| $H = trim($h); | ||
| $headers .= " -H '{$H}'"; | ||
| } | ||
| $this->curl_cmd = "curl -X {$http_op} {$headers} --connect-timeout {$this->conn_timeout} --max-time {$this->conn_timeout} -k '{$url}' --data-raw '{$rest_payload}'"; | ||
| debug_dump($this->curl_cmd, "HTTP REQUEST:\n"); | ||
|
|
||
| $ch = curl_init(); | ||
| curl_setopt($ch, CURLOPT_URL, $url); | ||
|
|
@@ -206,7 +212,7 @@ private function execute_curl_command($origin, $http_op, $url, $rest_payload, $c | |
| if ($http_code < 200 || $http_code > 209) { | ||
| $cmd_quote = str_replace("\"", "'", $body); | ||
| $cmd_return = str_replace("\n", "", $cmd_quote); | ||
| throw new SmsException("Call to API {$curl_cmd} Failed, header = $header, $cmd_return error", ERR_SD_CMDFAILED, $origin); | ||
| throw new SmsException("Call to API {$this->curl_cmd} Failed, header = $header, $cmd_return error", ERR_SD_CMDFAILED, $origin); | ||
| } | ||
|
|
||
| if (!isset($this->cookie)) { | ||
|
|
@@ -221,9 +227,10 @@ private function execute_curl_command($origin, $http_op, $url, $rest_payload, $c | |
| else | ||
| { | ||
| if ($http_code != 204) { | ||
| throw new SmsException ("$origin: Response to API {$curl_cmd} Failed, expected json received empty response, header $header", ERR_SD_CMDFAILED); | ||
| throw new SmsException ("$origin: Response to API {$this->curl_cmd} Failed, expected json received empty response, header $header", ERR_SD_CMDFAILED); | ||
| } | ||
| } | ||
| debug_dump($this->response, "HTTP RESPONSE:\n"); | ||
|
||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential null reference error. The function
is_error_xml()is called with$this->responsewhich may be null or unset. If the HTTP response is empty and the status code is 204, the response object is never initialized (see lines 229-231), but the error checking at line 157 will still execute. Add a check to ensure$this->responseis set before callingis_error_xml(), or handle null/unset values within theis_error_xml()function.