diff options
author | Alex Solomes <alex.solomes@softwareag.com> | 2022-06-24 15:55:32 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-24 15:55:32 +0100 |
commit | 9b8d8c8ecb081176350adefb9d3d2d468ba625d5 (patch) | |
tree | 2b05bace2c29b405dce4ba558e51368ad521e08b | |
parent | 2ab5aa4506979d350aba545882fad932fdec9b72 (diff) | |
parent | 35e15064810c79218d3e0a11989f4be1407c06c9 (diff) |
Merge pull request #1222 from initard/bugfix/1220/plugins-panic-if-incorrect-payload
Fixing plugins panic if incorrect payload
-rw-r--r-- | plugins/c8y_configuration_plugin/src/main.rs | 53 | ||||
-rw-r--r-- | plugins/c8y_log_plugin/src/main.rs | 21 |
2 files changed, 44 insertions, 30 deletions
diff --git a/plugins/c8y_configuration_plugin/src/main.rs b/plugins/c8y_configuration_plugin/src/main.rs index eb4b8272..96d2b020 100644 --- a/plugins/c8y_configuration_plugin/src/main.rs +++ b/plugins/c8y_configuration_plugin/src/main.rs @@ -151,31 +151,40 @@ async fn run( } else { match payload.split(',').next().unwrap_or_default() { "524" => { - let config_download_request = - SmartRestConfigDownloadRequest::from_smartrest(payload)?; - - handle_config_download_request( - &plugin_config, - config_download_request, - tmp_dir.clone(), - &mut mqtt_client, - http_client, - ) - .await + let maybe_config_download_request = + SmartRestConfigDownloadRequest::from_smartrest(payload); + if let Ok(config_download_request) = maybe_config_download_request { + handle_config_download_request( + &plugin_config, + config_download_request, + tmp_dir.clone(), + &mut mqtt_client, + http_client, + ) + .await + } else { + error!("Incorrect Download SmartREST payload: {}", payload); + Ok(()) + } } "526" => { // retrieve config file upload smartrest request from payload - let config_upload_request = - SmartRestConfigUploadRequest::from_smartrest(payload)?; - - // handle the config file upload request - handle_config_upload_request( - &plugin_config, - config_upload_request, - &mut mqtt_client, - http_client, - ) - .await + let maybe_config_upload_request = + SmartRestConfigUploadRequest::from_smartrest(payload); + + if let Ok(config_upload_request) = maybe_config_upload_request { + // handle the config file upload request + handle_config_upload_request( + &plugin_config, + config_upload_request, + &mut mqtt_client, + http_client, + ) + .await + } else { + error!("Incorrect Upload SmartREST payload: {}", payload); + Ok(()) + } } _ => { // Ignore operation messages not meant for this plugin diff --git a/plugins/c8y_log_plugin/src/main.rs b/plugins/c8y_log_plugin/src/main.rs index 8a04589f..42e28053 100644 --- a/plugins/c8y_log_plugin/src/main.rs +++ b/plugins/c8y_log_plugin/src/main.rs @@ -108,14 +108,19 @@ async fn run( "522" => { info!("Log request received: {payload}"); // retrieve smartrest object from payload - let smartrest_obj = SmartRestLogRequest::from_smartrest(payload)?; - handle_logfile_request_operation( - &smartrest_obj, - &plugin_config, - mqtt_client, - http_client, - ) - .await + let maybe_smartrest_obj = SmartRestLogRequest::from_smartrest(payload); + if let Ok(smartrest_obj) = maybe_smartrest_obj { + handle_logfile_request_operation( + &smartrest_obj, + &plugin_config, + mqtt_client, + http_client, + ) + .await + } else { + error!("Incorrect SmartREST payload: {}", payload); + Ok(()) + } } _ => { // Ignore operation messages not meant for this plugin |