From 40a5f15046ea8af02a6aed366d66a7178acf56d1 Mon Sep 17 00:00:00 2001 From: Matthias Suess Date: Wed, 27 Nov 2024 17:36:31 +0100 Subject: [PATCH 1/2] Harden message_callback against runtime error Signed-off-by: Matthias Suess --- lib/ocpp/v16/charge_point_impl.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/ocpp/v16/charge_point_impl.cpp b/lib/ocpp/v16/charge_point_impl.cpp index 3f1399590..afba8d9d8 100644 --- a/lib/ocpp/v16/charge_point_impl.cpp +++ b/lib/ocpp/v16/charge_point_impl.cpp @@ -1263,10 +1263,15 @@ void ChargePointImpl::message_callback(const std::string& message) { EVLOG_error << "Exception during handling of message: " << e.what(); this->message_dispatcher->dispatch_call_error( CallError(enhanced_message.uniqueId, "FormationViolation", e.what(), json({}))); + return; } catch (const json::exception& e) { EVLOG_error << "JSON exception during reception of message: " << e.what(); this->message_dispatcher->dispatch_call_error(CallError(MessageId("-1"), "GenericError", e.what(), json({}))); return; + } catch (const std::runtime_error& e) { + EVLOG_error << "runtime_error during reception of message: " << e.what(); + this->send(CallError(MessageId("-1"), "GenericError", e.what(), json({}))); + return; } auto json_message = enhanced_message.message; From 18a93cf506853b9aa3fc3405d5d382e02755430f Mon Sep 17 00:00:00 2001 From: Matthias Suess Date: Wed, 4 Dec 2024 14:17:43 +0100 Subject: [PATCH 2/2] Update related to dispatch_call Signed-off-by: Matthias Suess --- lib/ocpp/v16/charge_point_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ocpp/v16/charge_point_impl.cpp b/lib/ocpp/v16/charge_point_impl.cpp index afba8d9d8..e153d0d44 100644 --- a/lib/ocpp/v16/charge_point_impl.cpp +++ b/lib/ocpp/v16/charge_point_impl.cpp @@ -1270,7 +1270,7 @@ void ChargePointImpl::message_callback(const std::string& message) { return; } catch (const std::runtime_error& e) { EVLOG_error << "runtime_error during reception of message: " << e.what(); - this->send(CallError(MessageId("-1"), "GenericError", e.what(), json({}))); + this->message_dispatcher->dispatch_call_error(CallError(MessageId("-1"), "GenericError", e.what(), json({}))); return; }