From 5e967358322fabd34e66a34f2919588df3ebb33f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piet=20G=C3=B6mpel?= <37657534+Pietfried@users.noreply.github.com> Date: Tue, 12 Nov 2024 17:28:12 +0100 Subject: [PATCH] Fixed issue in EvseV2G and OCPP modules. The exiResponse is a required value in the OCPP type but its optional in the EVerest type. This could lead to the situation that the EvseV2G module receives an empty exiResponse that could lead to a segmentation fault. This commit only sets the exiResponse in OCPP when not empty and adds an additional check to EvseV2G to check if the exiResponse string is not empty (#961) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Piet Gömpel --- modules/EvseV2G/charger/ISO15118_chargerImpl.cpp | 2 +- modules/OCPP/OCPP.cpp | 6 +++++- modules/OCPP201/OCPP201.cpp | 11 +++++++---- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/modules/EvseV2G/charger/ISO15118_chargerImpl.cpp b/modules/EvseV2G/charger/ISO15118_chargerImpl.cpp index 55d585a85..a1ca76375 100644 --- a/modules/EvseV2G/charger/ISO15118_chargerImpl.cpp +++ b/modules/EvseV2G/charger/ISO15118_chargerImpl.cpp @@ -213,7 +213,7 @@ void ISO15118_chargerImpl::handle_session_setup(std::vectormqtt_lock); - if (exi_stream_status.exi_response.has_value()) { + if (exi_stream_status.exi_response.has_value() and not exi_stream_status.exi_response.value().empty()) { v2g_ctx->evse_v2g_data.cert_install_res_b64_buffer = std::string(exi_stream_status.exi_response.value()); } v2g_ctx->evse_v2g_data.cert_install_status = diff --git a/modules/OCPP/OCPP.cpp b/modules/OCPP/OCPP.cpp index 9c6ef24e4..889758469 100644 --- a/modules/OCPP/OCPP.cpp +++ b/modules/OCPP/OCPP.cpp @@ -761,8 +761,12 @@ void OCPP::ready() { const ocpp::v201::CertificateActionEnum& certificate_action) { types::iso15118_charger::ResponseExiStreamStatus response; response.status = conversions::to_everest_iso15118_charger_status(certificate_response.status); - response.exi_response.emplace(certificate_response.exiResponse.get()); response.certificate_action = conversions::to_everest_certificate_action_enum(certificate_action); + if (not certificate_response.exiResponse.get().empty()) { + // since exi_response is an optional in the EVerest type we only set it when not empty + response.exi_response.emplace(certificate_response.exiResponse.get()); + } + this->r_evse_manager.at(this->connector_evse_index_map.at(connector_id)) ->call_set_get_certificate_response(response); }); diff --git a/modules/OCPP201/OCPP201.cpp b/modules/OCPP201/OCPP201.cpp index 1a6772577..643134bca 100644 --- a/modules/OCPP201/OCPP201.cpp +++ b/modules/OCPP201/OCPP201.cpp @@ -795,10 +795,13 @@ void OCPP201::ready() { conversions::to_ocpp_get_15118_certificate_request(certificate_request)); EVLOG_debug << "Received response from get_15118_ev_certificate_request: " << ocpp_response; // transform response, inject action, send to associated EvseManager - const auto everest_response_status = - conversions::to_everest_iso15118_charger_status(ocpp_response.status); - const types::iso15118_charger::ResponseExiStreamStatus everest_response{ - everest_response_status, certificate_request.certificate_action, ocpp_response.exiResponse}; + types::iso15118_charger::ResponseExiStreamStatus everest_response; + everest_response.status = conversions::to_everest_iso15118_charger_status(ocpp_response.status); + everest_response.certificate_action = certificate_request.certificate_action; + if (not ocpp_response.exiResponse.get().empty()) { + // since exi_response is an optional in the EVerest type we only set it when not empty + everest_response.exi_response = ocpp_response.exiResponse.get(); + } this->r_evse_manager.at(evse_id - 1)->call_set_get_certificate_response(everest_response); });