mirror of
https://github.com/espressif/openthread.git
synced 2026-08-10 04:37:47 +00:00
[cli] avoid NULL dereference with udp send -s 0 command (#4164)
This commit is contained in:
+6
-4
@@ -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<uint16_t>(autoGenMessageLength));
|
||||
error = WriteCharToBuffer(message, static_cast<uint16_t>(autoGenPayloadLength));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user