@@ -470,6 +470,7 @@ STATIC OtaEventData_t * prvOTAEventBufferGet( void )
470
470
{
471
471
eventBuffer [ ulIndex ].bufferUsed = true;
472
472
pFreeBuffer = & eventBuffer [ ulIndex ];
473
+ pFreeBuffer -> dataLength = sizeof ( pFreeBuffer -> data );
473
474
break ;
474
475
}
475
476
}
@@ -616,13 +617,20 @@ STATIC void prvMqttJobCallback( void * pvIncomingPublishCallbackContext,
616
617
617
618
if ( pData != NULL )
618
619
{
619
- memcpy ( pData -> data , pxPublishInfo -> pPayload , pxPublishInfo -> payloadLength );
620
- pData -> dataLength = pxPublishInfo -> payloadLength ;
621
- eventMsg .eventId = OtaAgentEventReceivedJobDocument ;
622
- eventMsg .pEventData = pData ;
620
+ if ( ( size_t ) pData -> dataLength >= pxPublishInfo -> payloadLength )
621
+ {
622
+ memcpy ( pData -> data , pxPublishInfo -> pPayload , pxPublishInfo -> payloadLength );
623
+ pData -> dataLength = pxPublishInfo -> payloadLength ;
624
+ eventMsg .eventId = OtaAgentEventReceivedJobDocument ;
625
+ eventMsg .pEventData = pData ;
623
626
624
- /* Send job document received event. */
625
- OTA_SignalEvent ( & eventMsg );
627
+ /* Send job document received event. */
628
+ OTA_SignalEvent ( & eventMsg );
629
+ }
630
+ else
631
+ {
632
+ LogError ( ( "Error: OTA data buffers are too small for the Job message provided.\n" ) );
633
+ }
626
634
}
627
635
else
628
636
{
@@ -666,13 +674,20 @@ STATIC void prvMqttDataCallback( void * pvIncomingPublishCallbackContext,
666
674
667
675
if ( pxData != NULL )
668
676
{
669
- memcpy ( pxData -> data , pxPublishInfo -> pPayload , pxPublishInfo -> payloadLength );
670
- pxData -> dataLength = pxPublishInfo -> payloadLength ;
671
- eventMsg .eventId = OtaAgentEventReceivedFileBlock ;
672
- eventMsg .pEventData = pxData ;
677
+ if ( ( size_t ) pxData -> dataLength >= pxPublishInfo -> payloadLength )
678
+ {
679
+ memcpy ( pxData -> data , pxPublishInfo -> pPayload , pxPublishInfo -> payloadLength );
680
+ pxData -> dataLength = pxPublishInfo -> payloadLength ;
681
+ eventMsg .eventId = OtaAgentEventReceivedFileBlock ;
682
+ eventMsg .pEventData = pxData ;
673
683
674
- /* Send job document received event. */
675
- OTA_SignalEvent ( & eventMsg );
684
+ /* Send file block received event. */
685
+ OTA_SignalEvent ( & eventMsg );
686
+ }
687
+ else
688
+ {
689
+ LogError ( ( "Error: OTA data buffers are too small for the data message received.\n" ) );
690
+ }
676
691
}
677
692
else
678
693
{
@@ -762,6 +777,9 @@ STATIC void prvMQTTUnsubscribeCompleteCallback( MQTTAgentCommandContext_t * pxCo
762
777
}
763
778
}
764
779
780
+ /*
781
+ * Precondition: pTopicFilter is not null.
782
+ */
765
783
STATIC OtaMqttStatus_t prvMQTTSubscribe ( const char * pTopicFilter ,
766
784
uint16_t topicFilterLength ,
767
785
uint8_t ucQoS )
0 commit comments