[ncp] ensure IPv6 packet length does not exceed maximum size of SPINEL command payload (#4940)

With the current code, it is possible that NCP tries to send IPv6
packet larger than the maximum size of SPINEL command payload.

This commit adds additional defines to spinel.h and proper checks in
NCP codebase.
This commit is contained in:
Duda, Lukasz
2020-05-11 15:22:18 -07:00
committed by Jonathan Hui
parent c5b9c3efac
commit 9aa7340eb2
2 changed files with 25 additions and 0 deletions
+22
View File
@@ -345,8 +345,30 @@
#define SPINEL_PROTOCOL_VERSION_THREAD_MAJOR 4
#define SPINEL_PROTOCOL_VERSION_THREAD_MINOR 3
/**
* @def SPINEL_FRAME_MAX_SIZE
*
* The maximum size of SPINEL frame.
*
*/
#define SPINEL_FRAME_MAX_SIZE 1300
/**
* @def SPINEL_FRAME_MAX_COMMAND_HEADER_SIZE
*
* The maximum size of SPINEL command header.
*
*/
#define SPINEL_FRAME_MAX_COMMAND_HEADER_SIZE 4
/**
* @def SPINEL_FRAME_MAX_PAYLOAD_SIZE
*
* The maximum size of SPINEL command payload.
*
*/
#define SPINEL_FRAME_MAX_COMMAND_PAYLOAD_SIZE (SPINEL_FRAME_MAX_SIZE - SPINEL_FRAME_MAX_COMMAND_HEADER_SIZE)
/**
* @def SPINEL_ENCRYPTER_EXTRA_DATA_SIZE
*
+3
View File
@@ -3397,6 +3397,9 @@ void NcpBase::HandleDatagramFromStack(otMessage *aMessage)
{
VerifyOrExit(aMessage != NULL, OT_NOOP);
// Do not forward frames larger than SPINEL payload size.
VerifyOrExit(otMessageGetLength(aMessage) <= SPINEL_FRAME_MAX_COMMAND_PAYLOAD_SIZE, otMessageFree(aMessage));
otMessageQueueEnqueue(&mMessageQueue, aMessage);
// If there is no queued spinel command response, try to write/send