From 1fceb225b3858a990ffb6ce28f30b8b3dfba1614 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Feh=C3=A9r?= <82935051+feherdave@users.noreply.github.com> Date: Thu, 9 May 2024 16:41:54 +0200 Subject: [PATCH] [cli] add UDP socket openness check before sending with `udp send` (#10206) Problem: Executing the `udp send` command in CLI without previously opening the example udp socket results in an unhandled null-pointer exception. Solution: Before anything is processed in the `UdpExample::Process(Arg aArgs[])` method, the UDP socket is checked whether it's open or not. If not, the method returns with OT_ERROR_INVALID_STATE error avoiding the null-pointer exception. --- src/cli/cli_udp.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cli/cli_udp.cpp b/src/cli/cli_udp.cpp index 65e774f59..fba14f1c0 100644 --- a/src/cli/cli_udp.cpp +++ b/src/cli/cli_udp.cpp @@ -256,6 +256,8 @@ template <> otError UdpExample::Process(Arg aArgs[]) otMessageInfo messageInfo; otMessageSettings messageSettings = {mLinkSecurityEnabled, OT_MESSAGE_PRIORITY_NORMAL}; + VerifyOrExit(otUdpIsOpen(GetInstancePtr(), &mSocket), error = OT_ERROR_INVALID_STATE); + ClearAllBytes(messageInfo); // Possible argument formats: