[cli] avoid NULL dereference with udp send -s 0 command (#4164)

This commit is contained in:
Jonathan Hui
2019-09-16 18:08:47 -07:00
committed by GitHub
parent e4dc606ec8
commit 87ef3b1d51
+6 -4
View File
@@ -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
{