Skip to content

Commit

Permalink
Added received buffer size checks.
Browse files Browse the repository at this point in the history
  • Loading branch information
mluis1 committed Apr 16, 2020
1 parent 830a0f9 commit e3063a9
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/mac/LoRaMac.c
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,13 @@ static void ProcessRadioRxDone( void )
switch( macHdr.Bits.MType )
{
case FRAME_TYPE_JOIN_ACCEPT:
// Check if the received frame size is valid
if( size < LORAMAC_JOIN_ACCEPT_FRAME_MIN_SIZE )
{
MacCtx.McpsIndication.Status = LORAMAC_EVENT_INFO_STATUS_ERROR;
PrepareRxDoneAbort( );
return;
}
macMsgJoinAccept.Buffer = payload;
macMsgJoinAccept.BufSize = size;

Expand Down Expand Up @@ -1068,7 +1075,8 @@ static void ProcessRadioRxDone( void )
getPhy.Datarate = MacCtx.McpsIndication.RxDatarate;
getPhy.Attribute = PHY_MAX_PAYLOAD;
phyParam = RegionGetPhyParam( MacCtx.NvmCtx->Region, &getPhy );
if( MAX( 0, ( int16_t )( ( int16_t ) size - ( int16_t ) LORA_MAC_FRMPAYLOAD_OVERHEAD ) ) > ( int16_t )phyParam.Value )
if( ( MAX( 0, ( int16_t )( ( int16_t ) size - ( int16_t ) LORAMAC_FRAME_PAYLOAD_OVERHEAD_SIZE ) ) > ( int16_t )phyParam.Value ) ||
( size < LORAMAC_FRAME_PAYLOAD_MIN_SIZE ) )
{
MacCtx.McpsIndication.Status = LORAMAC_EVENT_INFO_STATUS_ERROR;
PrepareRxDoneAbort( );
Expand Down
6 changes: 6 additions & 0 deletions src/peripherals/atecc608a-tnglora-se/atecc608a-tnglora-se.c
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,12 @@ SecureElementStatus_t SecureElementProcessJoinAccept( JoinReqIdentifier_t joinRe
return SECURE_ELEMENT_ERROR_NPE;
}

// Check that frame size isn't bigger than a JoinAccept with CFList size
if( encJoinAcceptSize > LORAMAC_JOIN_ACCEPT_FRAME_MAX_SIZE )
{
return SECURE_ELEMENT_ERROR_BUF_SIZE;
}

// Determine decryption key
KeyIdentifier_t encKeyID = NWK_KEY;

Expand Down
6 changes: 6 additions & 0 deletions src/peripherals/lr1110-se/lr1110-se.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,12 @@ SecureElementStatus_t SecureElementProcessJoinAccept( JoinReqIdentifier_t joinRe
return SECURE_ELEMENT_ERROR_NPE;
}

// Check that frame size isn't bigger than a JoinAccept with CFList size
if( encJoinAcceptSize > LORAMAC_JOIN_ACCEPT_FRAME_MAX_SIZE )
{
return SECURE_ELEMENT_ERROR_BUF_SIZE;
}

// Determine decryption key
KeyIdentifier_t encKeyID = NWK_KEY;

Expand Down
6 changes: 6 additions & 0 deletions src/peripherals/soft-se/soft-se.c
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,12 @@ SecureElementStatus_t SecureElementProcessJoinAccept( JoinReqIdentifier_t joinRe
return SECURE_ELEMENT_ERROR_NPE;
}

// Check that frame size isn't bigger than a JoinAccept with CFList size
if( encJoinAcceptSize > LORAMAC_JOIN_ACCEPT_FRAME_MAX_SIZE )
{
return SECURE_ELEMENT_ERROR_BUF_SIZE;
}

// Determine decryption key
KeyIdentifier_t encKeyID = NWK_KEY;

Expand Down

0 comments on commit e3063a9

Please sign in to comment.