mirror of
https://github.com/espressif/openthread.git
synced 2026-07-29 23:27:46 +00:00
[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:
committed by
Jonathan Hui
parent
c5b9c3efac
commit
9aa7340eb2
@@ -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
|
||||
*
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user