From 87ef3b1d5105ac6225c9043a7be0137cdcc11cd5 Mon Sep 17 00:00:00 2001 From: Jonathan Hui Date: Mon, 16 Sep 2019 18:08:47 -0700 Subject: [PATCH] [cli] avoid NULL dereference with `udp send -s 0` command (#4164) --- src/cli/cli_udp.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/cli/cli_udp.cpp b/src/cli/cli_udp.cpp index 60f9ddba9..06a88ef83 100644 --- a/src/cli/cli_udp.cpp +++ b/src/cli/cli_udp.cpp @@ -138,7 +138,8 @@ otError UdpExample::ProcessSend(int argc, char *argv[]) otMessageInfo messageInfo; otMessage * message = NULL; int curArg = 0; - unsigned long autoGenMessageLength = 0; + bool autoGenPayload = false; + unsigned long autoGenPayloadLength = 0; memset(&messageInfo, 0, sizeof(messageInfo)); @@ -148,7 +149,8 @@ otError UdpExample::ProcessSend(int argc, char *argv[]) { if (strcmp(argv[curArg++], "-s") == 0) { - error = Interpreter::ParseUnsignedLong(argv[curArg++], autoGenMessageLength); + autoGenPayload = true; + error = Interpreter::ParseUnsignedLong(argv[curArg++], autoGenPayloadLength); SuccessOrExit(error); } else @@ -173,9 +175,9 @@ otError UdpExample::ProcessSend(int argc, char *argv[]) message = otUdpNewMessage(mInterpreter.mInstance, NULL); VerifyOrExit(message != NULL, error = OT_ERROR_NO_BUFS); - if (autoGenMessageLength != 0) + if (autoGenPayload) { - error = WriteCharToBuffer(message, static_cast(autoGenMessageLength)); + error = WriteCharToBuffer(message, static_cast(autoGenPayloadLength)); } else {