mirror of
https://github.com/g4klx/DMRGateway.git
synced 2026-04-06 15:04:16 +00:00
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.
This commit is contained in:
parent
0e04ebae0f
commit
c9a2d5802e
1 changed files with 8 additions and 1 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue