From c9a2d5802eacbb3c41df5bbe0698425b4ed0b174 Mon Sep 17 00:00:00 2001 From: Ember Date: Sat, 4 Apr 2026 16:47:58 -0700 Subject: [PATCH] Fix crash on empty MQTT command An empty or whitespace-only MQTT command message caused an unhandled std::out_of_range exception that terminated the process. Check for empty args before accessing. Also add null check on m_mqtt before publishing response. --- RemoteControl.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/RemoteControl.cpp b/RemoteControl.cpp index f41a334..670e076 100644 --- a/RemoteControl.cpp +++ b/RemoteControl.cpp @@ -62,6 +62,12 @@ REMOTE_COMMAND CRemoteControl::processCommand(const std::string& command) start = command.find_first_not_of(' ', end); } + if (m_args.empty()) { + if (m_mqtt != nullptr) + m_mqtt->publish("response", "KO"); + return REMOTE_COMMAND::NONE; + } + if (m_args.at(0U) == "enable" && m_args.size() >= ENABLE_ARGS) { if (m_args.at(1U) == "net1") m_command = REMOTE_COMMAND::ENABLE_NETWORK1; @@ -122,7 +128,8 @@ REMOTE_COMMAND CRemoteControl::processCommand(const std::string& command) #endif } - m_mqtt->publish("response", replyStr); + if (m_mqtt != nullptr) + m_mqtt->publish("response", replyStr); return m_command; }