@@ -135,7 +135,7 @@ static int32_t sendBuffer( MQTTContext_t * pContext,
135135static MQTTStatus_t sendConnectWithoutCopy ( MQTTContext_t * pContext ,
136136 const MQTTConnectInfo_t * pConnectInfo ,
137137 const MQTTPublishInfo_t * pWillInfo ,
138- size_t remainingLength ,
138+ uint32_t remainingLength ,
139139 const MQTTPropBuilder_t * pPropertyBuilder ,
140140 const MQTTPropBuilder_t * pWillPropertyBuilder );
141141
@@ -212,7 +212,7 @@ static MQTTStatus_t sendSubscribeWithoutCopy( MQTTContext_t * pContext,
212212 const MQTTSubscribeInfo_t * pSubscriptionList ,
213213 size_t subscriptionCount ,
214214 uint16_t packetId ,
215- size_t remainingLength ,
215+ uint32_t remainingLength ,
216216 const MQTTPropBuilder_t * pPropertyBuilder );
217217
218218/**
@@ -239,7 +239,7 @@ static MQTTStatus_t sendUnsubscribeWithoutCopy( MQTTContext_t * pContext,
239239 const MQTTSubscribeInfo_t * pSubscriptionList ,
240240 size_t subscriptionCount ,
241241 uint16_t packetId ,
242- size_t remainingLength ,
242+ uint32_t remainingLength ,
243243 const MQTTPropBuilder_t * pPropertyBuilder );
244244
245245/**
@@ -298,7 +298,7 @@ static int32_t recvExact( MQTTContext_t * pContext,
298298 * @return #MQTTRecvFailed or #MQTTNoDataAvailable.
299299 */
300300static MQTTStatus_t discardPacket ( MQTTContext_t * pContext ,
301- size_t remainingLength ,
301+ uint32_t remainingLength ,
302302 uint32_t timeoutMs );
303303
304304/**
@@ -702,7 +702,7 @@ static MQTTStatus_t validatePublishAckReasonCode( MQTTSuccessFailReasonCode_t re
702702
703703static MQTTStatus_t sendDisconnectWithoutCopy ( MQTTContext_t * pContext ,
704704 MQTTSuccessFailReasonCode_t * pReasonCode ,
705- size_t remainingLength ,
705+ uint32_t remainingLength ,
706706 const MQTTPropBuilder_t * pPropertyBuilder );
707707
708708/**
@@ -1238,7 +1238,7 @@ static int32_t recvExact( MQTTContext_t * pContext,
12381238/*-----------------------------------------------------------*/
12391239
12401240static MQTTStatus_t discardPacket ( MQTTContext_t * pContext ,
1241- size_t remainingLength ,
1241+ uint32_t remainingLength ,
12421242 uint32_t timeoutMs )
12431243{
12441244 MQTTStatus_t status = MQTTRecvFailed ;
@@ -1312,7 +1312,7 @@ static MQTTStatus_t discardStoredPacket( MQTTContext_t * pContext,
13121312 uint32_t totalBytesReceived = 0U ;
13131313 bool receiveError = false;
13141314 size_t mqttPacketSize = 0 ;
1315- size_t remainingLength ;
1315+ uint32_t remainingLength ;
13161316
13171317 assert ( pContext != NULL );
13181318 assert ( pPacketInfo != NULL );
@@ -1734,8 +1734,8 @@ static MQTTStatus_t sendPublishAcksWithProperty( MQTTContext_t * pContext,
17341734 * Reason Code + 1 = 8
17351735 */
17361736 uint8_t pubAckHeader [ 8U ];
1737- size_t remainingLength = 0U ;
1738- size_t packetSize = 0U ;
1737+ uint32_t remainingLength = 0U ;
1738+ uint32_t packetSize = 0U ;
17391739
17401740 /* The maximum vectors required to encode and send a publish ack.
17411741 * Ack Header 0 + 1 = 1
@@ -1846,7 +1846,7 @@ static MQTTStatus_t sendPublishAcksWithProperty( MQTTContext_t * pContext,
18461846 if ( bytesSentOrError != ( int32_t ) totalMessageLength )
18471847 {
18481848 LogError ( ( "Failed to send ACK packet: PacketType=%02x, "
1849- "PacketSize=%lu." ,
1849+ "PacketSize=%" PRIu32 ,
18501850 ( unsigned int ) packetTypeByte ,
18511851 packetSize ) );
18521852 status = MQTTSendFailed ;
@@ -2642,7 +2642,7 @@ static MQTTStatus_t sendSubscribeWithoutCopy( MQTTContext_t * pContext,
26422642 const MQTTSubscribeInfo_t * pSubscriptionList ,
26432643 size_t subscriptionCount ,
26442644 uint16_t packetId ,
2645- size_t remainingLength ,
2645+ uint32_t remainingLength ,
26462646 const MQTTPropBuilder_t * pPropertyBuilder )
26472647{
26482648 MQTTStatus_t status = MQTTSuccess ;
@@ -2783,7 +2783,7 @@ static MQTTStatus_t sendUnsubscribeWithoutCopy( MQTTContext_t * pContext,
27832783 const MQTTSubscribeInfo_t * pSubscriptionList ,
27842784 size_t subscriptionCount ,
27852785 uint16_t packetId ,
2786- size_t remainingLength ,
2786+ uint32_t remainingLength ,
27872787 const MQTTPropBuilder_t * pPropertyBuilder )
27882788{
27892789 MQTTStatus_t status = MQTTSuccess ;
@@ -3057,7 +3057,7 @@ static MQTTStatus_t sendPublishWithoutCopy( MQTTContext_t * pContext,
30573057static MQTTStatus_t sendConnectWithoutCopy ( MQTTContext_t * pContext ,
30583058 const MQTTConnectInfo_t * pConnectInfo ,
30593059 const MQTTPublishInfo_t * pWillInfo ,
3060- size_t remainingLength ,
3060+ uint32_t remainingLength ,
30613061 const MQTTPropBuilder_t * pPropertyBuilder ,
30623062 const MQTTPropBuilder_t * pWillPropertyBuilder )
30633063{
@@ -3810,7 +3810,7 @@ static MQTTStatus_t handleSubUnsubAck( MQTTContext_t * pContext,
38103810
38113811static MQTTStatus_t sendDisconnectWithoutCopy ( MQTTContext_t * pContext ,
38123812 MQTTSuccessFailReasonCode_t * pReasonCode ,
3813- size_t remainingLength ,
3813+ uint32_t remainingLength ,
38143814 const MQTTPropBuilder_t * pPropertyBuilder )
38153815{
38163816 int32_t bytesSentOrError ;
@@ -4335,7 +4335,8 @@ MQTTStatus_t MQTT_Subscribe( MQTTContext_t * pContext,
43354335 const MQTTPropBuilder_t * pPropertyBuilder )
43364336{
43374337 MQTTConnectionStatus_t connectStatus ;
4338- size_t remainingLength = 0UL , packetSize = 0UL ;
4338+ uint32_t remainingLength = 0UL ;
4339+ uint32_t packetSize = 0UL ;
43394340 MQTTStatus_t status = MQTTSuccess ;
43404341
43414342 status = validateSubscribeUnsubscribeParams ( pContext ,
@@ -4401,8 +4402,8 @@ MQTTStatus_t MQTT_Publish( MQTTContext_t * pContext,
44014402 const MQTTPropBuilder_t * pPropertyBuilder )
44024403{
44034404 size_t headerSize = 0UL ;
4404- size_t remainingLength = 0UL ;
4405- size_t packetSize = 0UL ;
4405+ uint32_t remainingLength = 0UL ;
4406+ uint32_t packetSize = 0UL ;
44064407 MQTTPublishState_t publishStatus = MQTTStateNull ;
44074408 MQTTConnectionStatus_t connectStatus ;
44084409 uint16_t topicAlias = 0U ;
@@ -4542,7 +4543,7 @@ MQTTStatus_t MQTT_Ping( MQTTContext_t * pContext )
45424543{
45434544 int32_t sendResult = 0 ;
45444545 MQTTStatus_t status = MQTTSuccess ;
4545- size_t packetSize = 0U ;
4546+ uint32_t packetSize = 0U ;
45464547 /* MQTT ping packets are of fixed length. */
45474548 uint8_t pingreqPacket [ 2U ];
45484549 MQTTFixedBuffer_t localBuffer ;
@@ -4634,7 +4635,8 @@ MQTTStatus_t MQTT_Unsubscribe( MQTTContext_t * pContext,
46344635 const MQTTPropBuilder_t * pPropertyBuilder )
46354636{
46364637 MQTTConnectionStatus_t connectStatus ;
4637- size_t remainingLength = 0UL , packetSize = 0UL ;
4638+ uint32_t remainingLength = 0UL ;
4639+ uint32_t packetSize = 0UL ;
46384640 MQTTStatus_t status = MQTTSuccess ;
46394641
46404642 /* Validate arguments. */
@@ -4697,8 +4699,8 @@ MQTTStatus_t MQTT_Disconnect( MQTTContext_t * pContext,
46974699 const MQTTPropBuilder_t * pPropertyBuilder ,
46984700 MQTTSuccessFailReasonCode_t * pReasonCode )
46994701{
4700- size_t packetSize = 0U ;
4701- size_t remainingLength = 0U ;
4702+ uint32_t packetSize = 0U ;
4703+ uint32_t remainingLength = 0U ;
47024704 MQTTStatus_t status = MQTTSuccess ;
47034705 MQTTConnectionStatus_t connectStatus ;
47044706
@@ -4850,9 +4852,9 @@ uint16_t MQTT_GetPacketId( MQTTContext_t * pContext )
48504852/*-----------------------------------------------------------*/
48514853
48524854MQTTStatus_t MQTT_MatchTopic ( const char * pTopicName ,
4853- const uint16_t topicNameLength ,
4855+ const size_t topicNameLength ,
48544856 const char * pTopicFilter ,
4855- const uint16_t topicFilterLength ,
4857+ const size_t topicFilterLength ,
48564858 bool * pIsMatch )
48574859{
48584860 MQTTStatus_t status = MQTTSuccess ;
@@ -4881,6 +4883,16 @@ MQTTStatus_t MQTT_MatchTopic( const char * pTopicName,
48814883 LogError ( ( "Invalid paramater: Output parameter, pIsMatch, is NULL" ) );
48824884 status = MQTTBadParameter ;
48834885 }
4886+ else if ( CHECK_SIZE_T_OVERFLOWS_16BIT ( topicNameLength ) )
4887+ {
4888+ LogError ( ( "topicNameLength must be fit in a 16-bit value (<65535)" ) );
4889+ status = MQTTBadParameter ;
4890+ }
4891+ else if ( CHECK_SIZE_T_OVERFLOWS_16BIT ( topicFilterLength ) )
4892+ {
4893+ LogError ( ( "topicFilterLength must be fit in a 16-bit value (<65535)" ) );
4894+ status = MQTTBadParameter ;
4895+ }
48844896 else
48854897 {
48864898 /* Check for an exact match if the incoming topic name and the registered
0 commit comments