Skip to content

Commit 4eece1e

Browse files
authored
Merge pull request #621 from thingsconnected/pullreq6
LoRaMacSerializerData buffer overflow fix
2 parents 5ab5a8e + d807b60 commit 4eece1e

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/mac/LoRaMacSerializer.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -134,19 +134,19 @@ LoRaMacSerializerStatus_t LoRaMacSerializerData( LoRaMacMessageData_t* macMsg )
134134
+ LORAMAC_FHDR_F_CTRL_FIELD_SIZE
135135
+ LORAMAC_FHDR_F_CNT_FIELD_SIZE;
136136

137-
if( macMsg->FRMPayloadSize == 0 )
137+
computedBufSize += macMsg->FHDR.FCtrl.Bits.FOptsLen;
138+
139+
if( macMsg->FRMPayloadSize > 0 )
138140
{
139-
if( macMsg->BufSize < computedBufSize )
140-
{
141-
return LORAMAC_SERIALIZER_ERROR_BUF_SIZE;
142-
}
141+
computedBufSize += LORAMAC_F_PORT_FIELD_SIZE;
143142
}
144-
else
145-
{ //If FRMPayload >0, FPort field is present.
146-
if( macMsg->BufSize < computedBufSize + macMsg->FHDR.FCtrl.Bits.FOptsLen + macMsg->FRMPayloadSize + LORAMAC_F_PORT_FIELD_SIZE )
147-
{
148-
return LORAMAC_SERIALIZER_ERROR_BUF_SIZE;
149-
}
143+
144+
computedBufSize += macMsg->FRMPayloadSize;
145+
computedBufSize += LORAMAC_MIC_FIELD_SIZE;
146+
147+
if( macMsg->BufSize < computedBufSize )
148+
{
149+
return LORAMAC_SERIALIZER_ERROR_BUF_SIZE;
150150
}
151151

152152
macMsg->Buffer[bufItr++] = macMsg->MHDR.Value;

0 commit comments

Comments
 (0)