diff --git a/docs/doxygen/include/size_table.md b/docs/doxygen/include/size_table.md index 6651d29a..f8f10a09 100644 --- a/docs/doxygen/include/size_table.md +++ b/docs/doxygen/include/size_table.md @@ -9,7 +9,7 @@ core_mqtt.c -
7.5K
+
7.6K
6.7K
@@ -19,8 +19,8 @@ core_mqtt_serializer.c -
8.8K
-
7.2K
+
9.1K
+
7.3K
core_mqtt_serializer_private.c @@ -29,8 +29,8 @@ core_mqtt_prop_serializer.c -
1.3K
-
1.1K
+
1.4K
+
1.2K
core_mqtt_prop_deserializer.c @@ -39,7 +39,7 @@ Total estimates -
21.4K
-
18.0K
+
21.9K
+
18.2K
diff --git a/source/core_mqtt.c b/source/core_mqtt.c index 1942d85a..e3a62707 100644 --- a/source/core_mqtt.c +++ b/source/core_mqtt.c @@ -135,7 +135,7 @@ static int32_t sendBuffer( MQTTContext_t * pContext, static MQTTStatus_t sendConnectWithoutCopy( MQTTContext_t * pContext, const MQTTConnectInfo_t * pConnectInfo, const MQTTPublishInfo_t * pWillInfo, - size_t remainingLength, + uint32_t remainingLength, const MQTTPropBuilder_t * pPropertyBuilder, const MQTTPropBuilder_t * pWillPropertyBuilder ); @@ -212,7 +212,7 @@ static MQTTStatus_t sendSubscribeWithoutCopy( MQTTContext_t * pContext, const MQTTSubscribeInfo_t * pSubscriptionList, size_t subscriptionCount, uint16_t packetId, - size_t remainingLength, + uint32_t remainingLength, const MQTTPropBuilder_t * pPropertyBuilder ); /** @@ -239,7 +239,7 @@ static MQTTStatus_t sendUnsubscribeWithoutCopy( MQTTContext_t * pContext, const MQTTSubscribeInfo_t * pSubscriptionList, size_t subscriptionCount, uint16_t packetId, - size_t remainingLength, + uint32_t remainingLength, const MQTTPropBuilder_t * pPropertyBuilder ); /** @@ -298,7 +298,7 @@ static int32_t recvExact( MQTTContext_t * pContext, * @return #MQTTRecvFailed or #MQTTNoDataAvailable. */ static MQTTStatus_t discardPacket( MQTTContext_t * pContext, - size_t remainingLength, + uint32_t remainingLength, uint32_t timeoutMs ); /** @@ -702,7 +702,7 @@ static MQTTStatus_t validatePublishAckReasonCode( MQTTSuccessFailReasonCode_t re static MQTTStatus_t sendDisconnectWithoutCopy( MQTTContext_t * pContext, MQTTSuccessFailReasonCode_t * pReasonCode, - size_t remainingLength, + uint32_t remainingLength, const MQTTPropBuilder_t * pPropertyBuilder ); /** @@ -1238,7 +1238,7 @@ static int32_t recvExact( MQTTContext_t * pContext, /*-----------------------------------------------------------*/ static MQTTStatus_t discardPacket( MQTTContext_t * pContext, - size_t remainingLength, + uint32_t remainingLength, uint32_t timeoutMs ) { MQTTStatus_t status = MQTTRecvFailed; @@ -1312,7 +1312,7 @@ static MQTTStatus_t discardStoredPacket( MQTTContext_t * pContext, uint32_t totalBytesReceived = 0U; bool receiveError = false; size_t mqttPacketSize = 0; - size_t remainingLength; + uint32_t remainingLength; assert( pContext != NULL ); assert( pPacketInfo != NULL ); @@ -1734,8 +1734,8 @@ static MQTTStatus_t sendPublishAcksWithProperty( MQTTContext_t * pContext, * Reason Code + 1 = 8 */ uint8_t pubAckHeader[ 8U ]; - size_t remainingLength = 0U; - size_t packetSize = 0U; + uint32_t remainingLength = 0U; + uint32_t packetSize = 0U; /* The maximum vectors required to encode and send a publish ack. * Ack Header 0 + 1 = 1 @@ -1846,7 +1846,7 @@ static MQTTStatus_t sendPublishAcksWithProperty( MQTTContext_t * pContext, if( bytesSentOrError != ( int32_t ) totalMessageLength ) { LogError( ( "Failed to send ACK packet: PacketType=%02x, " - "PacketSize=%lu.", + "PacketSize=%" PRIu32, ( unsigned int ) packetTypeByte, packetSize ) ); status = MQTTSendFailed; @@ -2642,7 +2642,7 @@ static MQTTStatus_t sendSubscribeWithoutCopy( MQTTContext_t * pContext, const MQTTSubscribeInfo_t * pSubscriptionList, size_t subscriptionCount, uint16_t packetId, - size_t remainingLength, + uint32_t remainingLength, const MQTTPropBuilder_t * pPropertyBuilder ) { MQTTStatus_t status = MQTTSuccess; @@ -2783,7 +2783,7 @@ static MQTTStatus_t sendUnsubscribeWithoutCopy( MQTTContext_t * pContext, const MQTTSubscribeInfo_t * pSubscriptionList, size_t subscriptionCount, uint16_t packetId, - size_t remainingLength, + uint32_t remainingLength, const MQTTPropBuilder_t * pPropertyBuilder ) { MQTTStatus_t status = MQTTSuccess; @@ -2942,6 +2942,10 @@ static MQTTStatus_t sendPublishWithoutCopy( MQTTContext_t * pContext, uint8_t * pIndex; TransportOutVector_t * iterator; + assert( pContext != NULL ); + assert( pPublishInfo != NULL ); + assert( !CHECK_SIZE_T_OVERFLOWS_16BIT( pPublishInfo->topicNameLength ) ); + /* The header is sent first. */ pIoVector[ 0U ].iov_base = pMqttHeader; pIoVector[ 0U ].iov_len = headerSize; @@ -3057,7 +3061,7 @@ static MQTTStatus_t sendPublishWithoutCopy( MQTTContext_t * pContext, static MQTTStatus_t sendConnectWithoutCopy( MQTTContext_t * pContext, const MQTTConnectInfo_t * pConnectInfo, const MQTTPublishInfo_t * pWillInfo, - size_t remainingLength, + uint32_t remainingLength, const MQTTPropBuilder_t * pPropertyBuilder, const MQTTPropBuilder_t * pWillPropertyBuilder ) { @@ -3065,7 +3069,7 @@ static MQTTStatus_t sendConnectWithoutCopy( MQTTContext_t * pContext, TransportOutVector_t * iterator; size_t ioVectorLength = 0U; uint32_t totalMessageLength = 0U; - size_t connectPropLen = 0U; + uint32_t connectPropLen = 0U; int32_t bytesSentOrError; uint8_t * pIndex; uint8_t serializedClientIDLength[ 2U ]; @@ -3108,6 +3112,11 @@ static MQTTStatus_t sendConnectWithoutCopy( MQTTContext_t * pContext, */ TransportOutVector_t pIoVector[ 15U ]; + if( pWillInfo != NULL ) + { + assert( !CHECK_SIZE_T_OVERFLOWS_16BIT( pWillInfo->topicNameLength ) ); + } + iterator = pIoVector; pIndex = connectPacketHeader; @@ -3144,6 +3153,9 @@ static MQTTStatus_t sendConnectWithoutCopy( MQTTContext_t * pContext, if( ( pPropertyBuilder != NULL ) && ( pPropertyBuilder->pBuffer != NULL ) ) { + assert( !CHECK_SIZE_T_OVERFLOWS_32BIT( pPropertyBuilder->currentIndex ) ); + assert( pPropertyBuilder->currentIndex < MQTT_REMAINING_LENGTH_INVALID ); + connectPropLen = pPropertyBuilder->currentIndex; } @@ -3556,6 +3568,11 @@ static MQTTStatus_t validatePublishParams( const MQTTContext_t * pContext, pPublishInfo->pPayload ) ); status = MQTTBadParameter; } + else if( CHECK_SIZE_T_OVERFLOWS_16BIT( pPublishInfo->topicNameLength ) ) + { + LogError( ( "Topic name length must be less than 65536." ) ); + status = MQTTBadParameter; + } else if( ( pContext->outgoingPublishRecords == NULL ) && ( pPublishInfo->qos > MQTTQoS0 ) ) { LogError( ( "Trying to publish a QoS > MQTTQoS0 packet when outgoing publishes " @@ -3587,6 +3604,13 @@ static MQTTStatus_t validateTopicFilter( const MQTTContext_t * pContext, status = MQTTBadParameter; } + if( ( status == MQTTSuccess ) && + CHECK_SIZE_T_OVERFLOWS_16BIT( pSubscriptionList[ iterator ].topicFilterLength ) ) + { + LogError( ( "Topic filter length must be less than 65536 for topic number %" PRIu32, ( uint32_t ) iterator ) ); + status = MQTTBadParameter; + } + if( ( status == MQTTSuccess ) && ( subscriptionType == MQTT_TYPE_SUBSCRIBE ) ) { if( pSubscriptionList[ iterator ].qos > MQTTQoS2 ) @@ -3810,7 +3834,7 @@ static MQTTStatus_t handleSubUnsubAck( MQTTContext_t * pContext, static MQTTStatus_t sendDisconnectWithoutCopy( MQTTContext_t * pContext, MQTTSuccessFailReasonCode_t * pReasonCode, - size_t remainingLength, + uint32_t remainingLength, const MQTTPropBuilder_t * pPropertyBuilder ) { int32_t bytesSentOrError; @@ -4335,7 +4359,8 @@ MQTTStatus_t MQTT_Subscribe( MQTTContext_t * pContext, const MQTTPropBuilder_t * pPropertyBuilder ) { MQTTConnectionStatus_t connectStatus; - size_t remainingLength = 0UL, packetSize = 0UL; + uint32_t remainingLength = 0UL; + uint32_t packetSize = 0UL; MQTTStatus_t status = MQTTSuccess; status = validateSubscribeUnsubscribeParams( pContext, @@ -4401,8 +4426,8 @@ MQTTStatus_t MQTT_Publish( MQTTContext_t * pContext, const MQTTPropBuilder_t * pPropertyBuilder ) { size_t headerSize = 0UL; - size_t remainingLength = 0UL; - size_t packetSize = 0UL; + uint32_t remainingLength = 0UL; + uint32_t packetSize = 0UL; MQTTPublishState_t publishStatus = MQTTStateNull; MQTTConnectionStatus_t connectStatus; uint16_t topicAlias = 0U; @@ -4542,7 +4567,7 @@ MQTTStatus_t MQTT_Ping( MQTTContext_t * pContext ) { int32_t sendResult = 0; MQTTStatus_t status = MQTTSuccess; - size_t packetSize = 0U; + uint32_t packetSize = 0U; /* MQTT ping packets are of fixed length. */ uint8_t pingreqPacket[ 2U ]; MQTTFixedBuffer_t localBuffer; @@ -4634,7 +4659,8 @@ MQTTStatus_t MQTT_Unsubscribe( MQTTContext_t * pContext, const MQTTPropBuilder_t * pPropertyBuilder ) { MQTTConnectionStatus_t connectStatus; - size_t remainingLength = 0UL, packetSize = 0UL; + uint32_t remainingLength = 0UL; + uint32_t packetSize = 0UL; MQTTStatus_t status = MQTTSuccess; /* Validate arguments. */ @@ -4697,8 +4723,8 @@ MQTTStatus_t MQTT_Disconnect( MQTTContext_t * pContext, const MQTTPropBuilder_t * pPropertyBuilder, MQTTSuccessFailReasonCode_t * pReasonCode ) { - size_t packetSize = 0U; - size_t remainingLength = 0U; + uint32_t packetSize = 0U; + uint32_t remainingLength = 0U; MQTTStatus_t status = MQTTSuccess; MQTTConnectionStatus_t connectStatus; @@ -4850,9 +4876,9 @@ uint16_t MQTT_GetPacketId( MQTTContext_t * pContext ) /*-----------------------------------------------------------*/ MQTTStatus_t MQTT_MatchTopic( const char * pTopicName, - const uint16_t topicNameLength, + const size_t topicNameLength, const char * pTopicFilter, - const uint16_t topicFilterLength, + const size_t topicFilterLength, bool * pIsMatch ) { MQTTStatus_t status = MQTTSuccess; @@ -4881,6 +4907,16 @@ MQTTStatus_t MQTT_MatchTopic( const char * pTopicName, LogError( ( "Invalid paramater: Output parameter, pIsMatch, is NULL" ) ); status = MQTTBadParameter; } + else if( CHECK_SIZE_T_OVERFLOWS_16BIT( topicNameLength ) ) + { + LogError( ( "topicNameLength must be fit in a 16-bit value (<65535)" ) ); + status = MQTTBadParameter; + } + else if( CHECK_SIZE_T_OVERFLOWS_16BIT( topicFilterLength ) ) + { + LogError( ( "topicFilterLength must be fit in a 16-bit value (<65535)" ) ); + status = MQTTBadParameter; + } else { /* Check for an exact match if the incoming topic name and the registered diff --git a/source/core_mqtt_prop_deserializer.c b/source/core_mqtt_prop_deserializer.c index 919b23bc..6ed69309 100644 --- a/source/core_mqtt_prop_deserializer.c +++ b/source/core_mqtt_prop_deserializer.c @@ -47,7 +47,7 @@ * @return MQTTSuccess if all the checks pass; */ static inline MQTTStatus_t checkPropBuilderParams( MQTTPropBuilder_t * mqttPropBuilder, - uint32_t * currentIndex ); + size_t * currentIndex ); /** * @brief Get a uint8 property value from the property builder. @@ -65,7 +65,7 @@ static inline MQTTStatus_t checkPropBuilderParams( MQTTPropBuilder_t * mqttPropB * #MQTTBadParameter if parameters are invalid or property ID doesn't match. */ static MQTTStatus_t getPropUint8( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex, + size_t * currentIndex, uint8_t propertyId, uint8_t * property ); @@ -85,7 +85,7 @@ static MQTTStatus_t getPropUint8( MQTTPropBuilder_t * pPropertyBuilder, * #MQTTBadParameter if parameters are invalid or property ID doesn't match. */ static MQTTStatus_t getPropUint16( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex, + size_t * currentIndex, uint8_t propertyId, uint16_t * property ); @@ -105,7 +105,7 @@ static MQTTStatus_t getPropUint16( MQTTPropBuilder_t * pPropertyBuilder, * #MQTTBadParameter if parameters are invalid or property ID doesn't match. */ static MQTTStatus_t getPropUint32( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex, + size_t * currentIndex, uint8_t propertyId, uint32_t * property ); @@ -126,15 +126,15 @@ static MQTTStatus_t getPropUint32( MQTTPropBuilder_t * pPropertyBuilder, * #MQTTBadParameter if parameters are invalid or property ID doesn't match. */ static MQTTStatus_t getPropUtf8( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex, + size_t * currentIndex, uint8_t propertyId, const char ** property, - uint16_t * propertyLength ); + size_t * propertyLength ); /*-----------------------------------------------------------*/ static inline MQTTStatus_t checkPropBuilderParams( MQTTPropBuilder_t * mqttPropBuilder, - uint32_t * currentIndex ) + size_t * currentIndex ) { MQTTStatus_t status = MQTTSuccess; @@ -160,7 +160,7 @@ static inline MQTTStatus_t checkPropBuilderParams( MQTTPropBuilder_t * mqttPropB /*-----------------------------------------------------------*/ static MQTTStatus_t getPropUint8( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex, + size_t * currentIndex, uint8_t propertyId, uint8_t * property ) { @@ -210,7 +210,7 @@ static MQTTStatus_t getPropUint8( MQTTPropBuilder_t * pPropertyBuilder, /*-----------------------------------------------------------*/ static MQTTStatus_t getPropUint16( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex, + size_t * currentIndex, uint8_t propertyId, uint16_t * property ) { @@ -263,7 +263,7 @@ static MQTTStatus_t getPropUint16( MQTTPropBuilder_t * pPropertyBuilder, /*-----------------------------------------------------------*/ static MQTTStatus_t getPropUint32( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex, + size_t * currentIndex, uint8_t propertyId, uint32_t * property ) { @@ -316,10 +316,10 @@ static MQTTStatus_t getPropUint32( MQTTPropBuilder_t * pPropertyBuilder, /*-----------------------------------------------------------*/ static MQTTStatus_t getPropUtf8( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex, + size_t * currentIndex, uint8_t propertyId, const char ** property, - uint16_t * propertyLength ) + size_t * propertyLength ) { MQTTStatus_t status = checkPropBuilderParams( pPropertyBuilder, currentIndex ); @@ -368,7 +368,7 @@ static MQTTStatus_t getPropUtf8( MQTTPropBuilder_t * pPropertyBuilder, /*-----------------------------------------------------------*/ MQTTStatus_t MQTT_GetNextPropertyType( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex, + size_t * currentIndex, uint8_t * property ) { MQTTStatus_t status = checkPropBuilderParams( pPropertyBuilder, currentIndex ); @@ -430,7 +430,7 @@ MQTTStatus_t MQTT_GetNextPropertyType( MQTTPropBuilder_t * pPropertyBuilder, /*-----------------------------------------------------------*/ MQTTStatus_t MQTT_SkipNextProperty( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex ) + size_t * currentIndex ) { MQTTStatus_t status = checkPropBuilderParams( pPropertyBuilder, currentIndex ); uint8_t property; @@ -441,7 +441,7 @@ MQTTStatus_t MQTT_SkipNextProperty( MQTTPropBuilder_t * pPropertyBuilder, uint16_t dummyUint16; uint8_t dummyUint8; const char * dummyString; - uint16_t dummyStringLen; + size_t dummyStringLen; if( status != MQTTSuccess ) { @@ -541,7 +541,7 @@ MQTTStatus_t MQTT_SkipNextProperty( MQTTPropBuilder_t * pPropertyBuilder, /*-----------------------------------------------------------*/ MQTTStatus_t MQTTPropGet_UserProp( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex, + size_t * currentIndex, MQTTUserProperty_t * pUserProperty ) { MQTTStatus_t status = checkPropBuilderParams( pPropertyBuilder, currentIndex ); @@ -594,7 +594,7 @@ MQTTStatus_t MQTTPropGet_UserProp( MQTTPropBuilder_t * pPropertyBuilder, /*-----------------------------------------------------------*/ MQTTStatus_t MQTTPropGet_SessionExpiry( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex, + size_t * currentIndex, uint32_t * pSessionExpiry ) { return getPropUint32( pPropertyBuilder, currentIndex, MQTT_SESSION_EXPIRY_ID, pSessionExpiry ); @@ -603,7 +603,7 @@ MQTTStatus_t MQTTPropGet_SessionExpiry( MQTTPropBuilder_t * pPropertyBuilder, /*-----------------------------------------------------------*/ MQTTStatus_t MQTTPropGet_ReceiveMax( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex, + size_t * currentIndex, uint16_t * pReceiveMax ) { return getPropUint16( pPropertyBuilder, currentIndex, MQTT_RECEIVE_MAX_ID, pReceiveMax ); @@ -612,7 +612,7 @@ MQTTStatus_t MQTTPropGet_ReceiveMax( MQTTPropBuilder_t * pPropertyBuilder, /*-----------------------------------------------------------*/ MQTTStatus_t MQTTPropGet_MaxQos( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex, + size_t * currentIndex, uint8_t * pMaxQos ) { return getPropUint8( pPropertyBuilder, currentIndex, MQTT_MAX_QOS_ID, pMaxQos ); @@ -621,7 +621,7 @@ MQTTStatus_t MQTTPropGet_MaxQos( MQTTPropBuilder_t * pPropertyBuilder, /*-----------------------------------------------------------*/ MQTTStatus_t MQTTPropGet_RetainAvailable( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex, + size_t * currentIndex, uint8_t * pRetainAvailable ) { return getPropUint8( pPropertyBuilder, currentIndex, MQTT_RETAIN_AVAILABLE_ID, pRetainAvailable ); @@ -630,7 +630,7 @@ MQTTStatus_t MQTTPropGet_RetainAvailable( MQTTPropBuilder_t * pPropertyBuilder, /*-----------------------------------------------------------*/ MQTTStatus_t MQTTPropGet_MaxPacketSize( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex, + size_t * currentIndex, uint32_t * pMaxPacketSize ) { return getPropUint32( pPropertyBuilder, currentIndex, MQTT_MAX_PACKET_SIZE_ID, pMaxPacketSize ); @@ -639,9 +639,9 @@ MQTTStatus_t MQTTPropGet_MaxPacketSize( MQTTPropBuilder_t * pPropertyBuilder, /*-----------------------------------------------------------*/ MQTTStatus_t MQTTPropGet_AssignedClientId( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex, + size_t * currentIndex, const char ** pClientId, - uint16_t * pClientIdLength ) + size_t * pClientIdLength ) { return getPropUtf8( pPropertyBuilder, currentIndex, MQTT_ASSIGNED_CLIENT_ID, pClientId, pClientIdLength ); } @@ -649,7 +649,7 @@ MQTTStatus_t MQTTPropGet_AssignedClientId( MQTTPropBuilder_t * pPropertyBuilder, /*-----------------------------------------------------------*/ MQTTStatus_t MQTTPropGet_TopicAliasMax( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex, + size_t * currentIndex, uint16_t * pTopicAliasMax ) { return getPropUint16( pPropertyBuilder, currentIndex, MQTT_TOPIC_ALIAS_MAX_ID, pTopicAliasMax ); @@ -658,9 +658,9 @@ MQTTStatus_t MQTTPropGet_TopicAliasMax( MQTTPropBuilder_t * pPropertyBuilder, /*-----------------------------------------------------------*/ MQTTStatus_t MQTTPropGet_ReasonString( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex, + size_t * currentIndex, const char ** pReasonString, - uint16_t * pReasonStringLength ) + size_t * pReasonStringLength ) { return getPropUtf8( pPropertyBuilder, currentIndex, MQTT_REASON_STRING_ID, pReasonString, pReasonStringLength ); } @@ -668,7 +668,7 @@ MQTTStatus_t MQTTPropGet_ReasonString( MQTTPropBuilder_t * pPropertyBuilder, /*-----------------------------------------------------------*/ MQTTStatus_t MQTTPropGet_WildcardId( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex, + size_t * currentIndex, uint8_t * pWildcardAvailable ) { return getPropUint8( pPropertyBuilder, currentIndex, MQTT_WILDCARD_ID, pWildcardAvailable ); @@ -677,7 +677,7 @@ MQTTStatus_t MQTTPropGet_WildcardId( MQTTPropBuilder_t * pPropertyBuilder, /*-----------------------------------------------------------*/ MQTTStatus_t MQTTPropGet_SubsIdAvailable( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex, + size_t * currentIndex, uint8_t * pSubsIdAvailable ) { return getPropUint8( pPropertyBuilder, currentIndex, MQTT_SUB_AVAILABLE_ID, pSubsIdAvailable ); @@ -686,7 +686,7 @@ MQTTStatus_t MQTTPropGet_SubsIdAvailable( MQTTPropBuilder_t * pPropertyBuilder, /*-----------------------------------------------------------*/ MQTTStatus_t MQTTPropGet_SharedSubAvailable( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex, + size_t * currentIndex, uint8_t * pSharedSubAvailable ) { return getPropUint8( pPropertyBuilder, currentIndex, MQTT_SHARED_SUB_ID, pSharedSubAvailable ); @@ -695,7 +695,7 @@ MQTTStatus_t MQTTPropGet_SharedSubAvailable( MQTTPropBuilder_t * pPropertyBuilde /*-----------------------------------------------------------*/ MQTTStatus_t MQTTPropGet_ServerKeepAlive( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex, + size_t * currentIndex, uint16_t * pServerKeepAlive ) { return getPropUint16( pPropertyBuilder, currentIndex, MQTT_SERVER_KEEP_ALIVE_ID, pServerKeepAlive ); @@ -704,9 +704,9 @@ MQTTStatus_t MQTTPropGet_ServerKeepAlive( MQTTPropBuilder_t * pPropertyBuilder, /*-----------------------------------------------------------*/ MQTTStatus_t MQTTPropGet_ResponseInfo( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex, + size_t * currentIndex, const char ** pResponseInfo, - uint16_t * pResponseInfoLength ) + size_t * pResponseInfoLength ) { return getPropUtf8( pPropertyBuilder, currentIndex, MQTT_RESPONSE_INFO_ID, pResponseInfo, pResponseInfoLength ); } @@ -714,9 +714,9 @@ MQTTStatus_t MQTTPropGet_ResponseInfo( MQTTPropBuilder_t * pPropertyBuilder, /*-----------------------------------------------------------*/ MQTTStatus_t MQTTPropGet_ServerRef( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex, + size_t * currentIndex, const char ** pServerRef, - uint16_t * pServerRefLength ) + size_t * pServerRefLength ) { return getPropUtf8( pPropertyBuilder, currentIndex, MQTT_SERVER_REF_ID, pServerRef, pServerRefLength ); } @@ -724,9 +724,9 @@ MQTTStatus_t MQTTPropGet_ServerRef( MQTTPropBuilder_t * pPropertyBuilder, /*-----------------------------------------------------------*/ MQTTStatus_t MQTTPropGet_AuthMethod( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex, + size_t * currentIndex, const char ** pAuthMethod, - uint16_t * pAuthMethodLen ) + size_t * pAuthMethodLen ) { return getPropUtf8( pPropertyBuilder, currentIndex, MQTT_AUTH_METHOD_ID, pAuthMethod, pAuthMethodLen ); } @@ -734,9 +734,9 @@ MQTTStatus_t MQTTPropGet_AuthMethod( MQTTPropBuilder_t * pPropertyBuilder, /*-----------------------------------------------------------*/ MQTTStatus_t MQTTPropGet_AuthData( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex, + size_t * currentIndex, const char ** pAuthData, - uint16_t * pAuthDataLen ) + size_t * pAuthDataLen ) { return getPropUtf8( pPropertyBuilder, currentIndex, MQTT_AUTH_DATA_ID, pAuthData, pAuthDataLen ); } @@ -744,7 +744,7 @@ MQTTStatus_t MQTTPropGet_AuthData( MQTTPropBuilder_t * pPropertyBuilder, /*-----------------------------------------------------------*/ MQTTStatus_t MQTTPropGet_PayloadFormatIndicator( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex, + size_t * currentIndex, uint8_t * pPayloadFormat ) { return getPropUint8( pPropertyBuilder, currentIndex, MQTT_PAYLOAD_FORMAT_ID, pPayloadFormat ); @@ -753,7 +753,7 @@ MQTTStatus_t MQTTPropGet_PayloadFormatIndicator( MQTTPropBuilder_t * pPropertyBu /*-----------------------------------------------------------*/ MQTTStatus_t MQTTPropGet_MessageExpiryInterval( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex, + size_t * currentIndex, uint32_t * pMessageExpiry ) { return getPropUint32( pPropertyBuilder, currentIndex, MQTT_MSG_EXPIRY_ID, pMessageExpiry ); @@ -762,7 +762,7 @@ MQTTStatus_t MQTTPropGet_MessageExpiryInterval( MQTTPropBuilder_t * pPropertyBui /*-----------------------------------------------------------*/ MQTTStatus_t MQTTPropGet_TopicAlias( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex, + size_t * currentIndex, uint16_t * pTopicAlias ) { return getPropUint16( pPropertyBuilder, currentIndex, MQTT_TOPIC_ALIAS_ID, pTopicAlias ); @@ -771,9 +771,9 @@ MQTTStatus_t MQTTPropGet_TopicAlias( MQTTPropBuilder_t * pPropertyBuilder, /*-----------------------------------------------------------*/ MQTTStatus_t MQTTPropGet_ResponseTopic( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex, + size_t * currentIndex, const char ** pResponseTopic, - uint16_t * pResponseTopicLength ) + size_t * pResponseTopicLength ) { return getPropUtf8( pPropertyBuilder, currentIndex, MQTT_RESPONSE_TOPIC_ID, pResponseTopic, pResponseTopicLength ); } @@ -781,9 +781,9 @@ MQTTStatus_t MQTTPropGet_ResponseTopic( MQTTPropBuilder_t * pPropertyBuilder, /*-----------------------------------------------------------*/ MQTTStatus_t MQTTPropGet_CorrelationData( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex, + size_t * currentIndex, const char ** pCorrelationData, - uint16_t * pCorrelationDataLength ) + size_t * pCorrelationDataLength ) { return getPropUtf8( pPropertyBuilder, currentIndex, MQTT_CORRELATION_DATA_ID, pCorrelationData, pCorrelationDataLength ); } @@ -791,7 +791,7 @@ MQTTStatus_t MQTTPropGet_CorrelationData( MQTTPropBuilder_t * pPropertyBuilder, /*-----------------------------------------------------------*/ MQTTStatus_t MQTTPropGet_SubscriptionId( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex, + size_t * currentIndex, uint32_t * pSubscriptionId ) { MQTTStatus_t status = checkPropBuilderParams( pPropertyBuilder, currentIndex ); @@ -838,9 +838,9 @@ MQTTStatus_t MQTTPropGet_SubscriptionId( MQTTPropBuilder_t * pPropertyBuilder, /*-----------------------------------------------------------*/ MQTTStatus_t MQTTPropGet_ContentType( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex, + size_t * currentIndex, const char ** pContentType, - uint16_t * pContentTypeLength ) + size_t * pContentTypeLength ) { return getPropUtf8( pPropertyBuilder, currentIndex, MQTT_CONTENT_TYPE_ID, pContentType, pContentTypeLength ); } diff --git a/source/core_mqtt_prop_serializer.c b/source/core_mqtt_prop_serializer.c index e4c99ed5..ae0aa6a0 100644 --- a/source/core_mqtt_prop_serializer.c +++ b/source/core_mqtt_prop_serializer.c @@ -138,7 +138,7 @@ static MQTTStatus_t addPropUint32( MQTTPropBuilder_t * pPropertyBuilder, */ static MQTTStatus_t addPropUtf8( MQTTPropBuilder_t * pPropertyBuilder, const char * property, - uint16_t propertyLength, + size_t propertyLength, uint8_t propId, uint8_t fieldPosition, const uint8_t * pOptionalMqttPacketType ); @@ -526,7 +526,7 @@ static MQTTStatus_t addPropUint32( MQTTPropBuilder_t * pPropertyBuilder, static MQTTStatus_t addPropUtf8( MQTTPropBuilder_t * pPropertyBuilder, const char * property, - uint16_t propertyLength, + size_t propertyLength, uint8_t propId, uint8_t fieldPosition, const uint8_t * pOptionalMqttPacketType ) @@ -534,6 +534,8 @@ static MQTTStatus_t addPropUtf8( MQTTPropBuilder_t * pPropertyBuilder, uint8_t * pIndex; MQTTStatus_t status = MQTTSuccess; + assert( !CHECK_SIZE_T_OVERFLOWS_16BIT( propertyLength ) ); + if( pPropertyBuilder == NULL ) { LogError( ( "Argument pPropertyBuilder cannot be NULL." ) ); @@ -684,11 +686,11 @@ MQTTStatus_t MQTTPropAdd_UserProp( MQTTPropBuilder_t * pPropertyBuilder, { LogError( ( "Arguments cannot be NULL: pUserProperties->userProperty->pKey=%p, " "pUserProperties->userProperty->pValue=%p, " - "Key Length = %u, Value Length = %u", + "Key Length = %d, Value Length = %d", ( void * ) userProperty->pKey, ( void * ) userProperty->pValue, - userProperty->keyLength, - userProperty->valueLength ) ); + ( int ) userProperty->keyLength, + ( int ) userProperty->valueLength ) ); status = MQTTBadParameter; } else if( ( pOptionalMqttPacketType != NULL ) && @@ -848,23 +850,35 @@ MQTTStatus_t MQTTPropAdd_RequestProbInfo( MQTTPropBuilder_t * pPropertyBuilder, MQTTStatus_t MQTTPropAdd_AuthMethod( MQTTPropBuilder_t * pPropertyBuilder, const char * authMethod, - uint16_t authMethodLength, + size_t authMethodLength, const uint8_t * pOptionalMqttPacketType ) { - /* Auth method has no restrictions and hence no additional checks required. */ - return addPropUtf8( pPropertyBuilder, - authMethod, - authMethodLength, - MQTT_AUTH_METHOD_ID, - MQTT_AUTHENTICATION_METHOD_POS, - pOptionalMqttPacketType ); + MQTTStatus_t status; + + if( CHECK_SIZE_T_OVERFLOWS_16BIT( authMethodLength ) ) + { + LogError( ( "Auth method length must be less than 65536 according to MQTT spec." ) ); + status = MQTTBadParameter; + } + else + { + /* Auth method has no restrictions and hence no additional checks required. */ + status = addPropUtf8( pPropertyBuilder, + authMethod, + authMethodLength, + MQTT_AUTH_METHOD_ID, + MQTT_AUTHENTICATION_METHOD_POS, + pOptionalMqttPacketType ); + } + + return status; } /*-----------------------------------------------------------*/ MQTTStatus_t MQTTPropAdd_AuthData( MQTTPropBuilder_t * pPropertyBuilder, const char * authData, - uint16_t authDataLength, + size_t authDataLength, const uint8_t * pOptionalMqttPacketType ) { MQTTStatus_t status = MQTTSuccess; @@ -890,6 +904,11 @@ MQTTStatus_t MQTTPropAdd_AuthData( MQTTPropBuilder_t * pPropertyBuilder, "Not a protocol violation but a practice enforced by coreMQTT." ) ); status = MQTTBadParameter; } + else if( CHECK_SIZE_T_OVERFLOWS_16BIT( authDataLength ) ) + { + LogError( ( "Auth data length must be less than 65536 according to MQTT spec." ) ); + status = MQTTBadParameter; + } else { status = addPropUtf8( pPropertyBuilder, @@ -971,7 +990,7 @@ MQTTStatus_t MQTTPropAdd_TopicAlias( MQTTPropBuilder_t * pPropertyBuilder, MQTTStatus_t MQTTPropAdd_ResponseTopic( MQTTPropBuilder_t * pPropertyBuilder, const char * responseTopic, - uint16_t responseTopicLength, + size_t responseTopicLength, const uint8_t * pOptionalMqttPacketType ) { MQTTStatus_t status; @@ -983,7 +1002,7 @@ MQTTStatus_t MQTTPropAdd_ResponseTopic( MQTTPropBuilder_t * pPropertyBuilder, } else if( responseTopicLength == 0U ) { - LogError( ( "Response Topic Length cannot be 0" ) ); + LogError( ( "Response Topic Length cannot be 0." ) ); status = MQTTBadParameter; } else if( ( memchr( ( void * ) responseTopic, ( int ) '#', responseTopicLength ) != NULL ) || @@ -992,6 +1011,11 @@ MQTTStatus_t MQTTPropAdd_ResponseTopic( MQTTPropBuilder_t * pPropertyBuilder, LogError( ( "Protocol Error : Response Topic contains wildcards (such as # or +)." ) ); status = MQTTBadParameter; } + else if( CHECK_SIZE_T_OVERFLOWS_16BIT( responseTopicLength ) ) + { + LogError( ( "Response topic length must be less than 65536 according to MQTT spec." ) ); + status = MQTTBadParameter; + } else { status = addPropUtf8( pPropertyBuilder, @@ -1009,46 +1033,82 @@ MQTTStatus_t MQTTPropAdd_ResponseTopic( MQTTPropBuilder_t * pPropertyBuilder, MQTTStatus_t MQTTPropAdd_CorrelationData( MQTTPropBuilder_t * pPropertyBuilder, const void * pCorrelationData, - uint16_t correlationLength, + size_t correlationLength, const uint8_t * pOptionalMqttPacketType ) { - /* Encoding binary and UTF-8 strings behaves in the same way. */ - return addPropUtf8( pPropertyBuilder, - ( const char * ) pCorrelationData, - correlationLength, - MQTT_CORRELATION_DATA_ID, - MQTT_CORRELATION_DATA_POS, - pOptionalMqttPacketType ); + MQTTStatus_t status; + + if( CHECK_SIZE_T_OVERFLOWS_16BIT( correlationLength ) ) + { + LogError( ( "Correlation data length must be less than 65536 according to MQTT spec." ) ); + status = MQTTBadParameter; + } + else + { + /* Encoding binary and UTF-8 strings behaves in the same way. */ + status = addPropUtf8( pPropertyBuilder, + ( const char * ) pCorrelationData, + correlationLength, + MQTT_CORRELATION_DATA_ID, + MQTT_CORRELATION_DATA_POS, + pOptionalMqttPacketType ); + } + + return status; } /*-----------------------------------------------------------*/ MQTTStatus_t MQTTPropAdd_ContentType( MQTTPropBuilder_t * pPropertyBuilder, const char * contentType, - uint16_t contentTypeLength, + size_t contentTypeLength, const uint8_t * pOptionalMqttPacketType ) { - /* No restriction and hence no additional checks on the content type. */ - return addPropUtf8( pPropertyBuilder, - contentType, - contentTypeLength, - MQTT_CONTENT_TYPE_ID, - MQTT_CONTENT_TYPE_POS, - pOptionalMqttPacketType ); + MQTTStatus_t status; + + if( CHECK_SIZE_T_OVERFLOWS_16BIT( contentTypeLength ) ) + { + LogError( ( "Content type string length must be less than 65536 according to MQTT spec." ) ); + status = MQTTBadParameter; + } + else + { + /* No restriction and hence no additional checks on the content type. */ + status = addPropUtf8( pPropertyBuilder, + contentType, + contentTypeLength, + MQTT_CONTENT_TYPE_ID, + MQTT_CONTENT_TYPE_POS, + pOptionalMqttPacketType ); + } + + return status; } /*-----------------------------------------------------------*/ MQTTStatus_t MQTTPropAdd_ReasonString( MQTTPropBuilder_t * pPropertyBuilder, const char * pReasonString, - uint16_t reasonStringLength, + size_t reasonStringLength, const uint8_t * pOptionalMqttPacketType ) { - /* No restriction and hence no additional checks on the reason string. */ - return addPropUtf8( pPropertyBuilder, - pReasonString, - reasonStringLength, - MQTT_REASON_STRING_ID, - MQTT_REASON_STRING_POS, - pOptionalMqttPacketType ); + MQTTStatus_t status; + + if( CHECK_SIZE_T_OVERFLOWS_16BIT( reasonStringLength ) ) + { + LogError( ( "Reason string length must be less than 65536 according to MQTT spec." ) ); + status = MQTTBadParameter; + } + else + { + /* No restriction and hence no additional checks on the reason string. */ + status = addPropUtf8( pPropertyBuilder, + pReasonString, + reasonStringLength, + MQTT_REASON_STRING_ID, + MQTT_REASON_STRING_POS, + pOptionalMqttPacketType ); + } + + return status; } diff --git a/source/core_mqtt_serializer.c b/source/core_mqtt_serializer.c index cf8e1a36..6c14907c 100644 --- a/source/core_mqtt_serializer.c +++ b/source/core_mqtt_serializer.c @@ -116,7 +116,7 @@ */ static void serializePublishCommon( const MQTTPublishInfo_t * pPublishInfo, const MQTTPropBuilder_t * pPublishProperties, - size_t remainingLength, + uint32_t remainingLength, uint16_t packetIdentifier, const MQTTFixedBuffer_t * pFixedBuffer, bool serializePayload ); @@ -136,10 +136,10 @@ static void serializePublishCommon( const MQTTPublishInfo_t * pPublishInfo, * MQTT spec; MQTTSuccess otherwise. */ static MQTTStatus_t calculatePublishPacketSize( const MQTTPublishInfo_t * pPublishInfo, - size_t * pRemainingLength, - size_t * pPacketSize, + uint32_t * pRemainingLength, + uint32_t * pPacketSize, uint32_t maxPacketSize, - size_t publishPropertyLength ); + uint32_t publishPropertyLength ); /** * @brief Calculates the packet size and remaining length of an MQTT @@ -162,9 +162,9 @@ static MQTTStatus_t calculatePublishPacketSize( const MQTTPublishInfo_t * pPubli static MQTTStatus_t calculateSubscriptionPacketSize( const MQTTSubscribeInfo_t * pSubscriptionList, size_t subscriptionCount, - size_t * pRemainingLength, - size_t * pPacketSize, - size_t subscribePropLen, + uint32_t * pRemainingLength, + uint32_t * pPacketSize, + uint32_t subscribePropLen, uint32_t maxPacketSize, MQTTSubscriptionType_t subscriptionType ); @@ -185,7 +185,7 @@ static MQTTStatus_t calculateSubscriptionPacketSize( const MQTTSubscribeInfo_t * static MQTTStatus_t validateSubscriptionSerializeParams( const MQTTSubscribeInfo_t * pSubscriptionList, size_t subscriptionCount, uint16_t packetId, - size_t remainingLength, + uint32_t remainingLength, const MQTTFixedBuffer_t * pFixedBuffer ); /** @@ -220,7 +220,7 @@ static void logConnackResponse( uint8_t responseCode ); * * @return The size of the remaining length if it were to be encoded. */ -static size_t remainingLengthEncodedSize( size_t length ); +static size_t remainingLengthEncodedSize( uint32_t length ); /** * @brief Retrieves and decodes the Remaining Length from the network interface @@ -274,9 +274,9 @@ static bool incomingPacketValid( uint8_t packetType ); * * @return #MQTTSuccess or #MQTTBadResponse. */ -static MQTTStatus_t checkPublishRemainingLength( size_t remainingLength, +static MQTTStatus_t checkPublishRemainingLength( uint32_t remainingLength, MQTTQoS_t qos, - size_t qos0Minimum ); + uint32_t qos0Minimum ); /** * @brief Process the flags of an incoming PUBLISH packet. @@ -418,7 +418,7 @@ static MQTTStatus_t deserializeConnackProperties( MQTTConnectionProperties_t * p static MQTTStatus_t deserializeSubUnsubAckProperties( MQTTPropBuilder_t * pPropBuffer, uint8_t * pIndex, size_t * pSubackPropertyLength, - size_t remainingLength ); + uint32_t remainingLength ); /** * @brief Deserialize an PUBACK, PUBREC, PUBREL, or PUBCOMP packet. @@ -452,7 +452,7 @@ static MQTTStatus_t deserializePubAcks( const MQTTPacketInfo_t * pAck, **/ static MQTTStatus_t decodePubAckProperties( MQTTPropBuilder_t * pPropBuffer, uint8_t * pIndex, - size_t remainingLength ); + uint32_t remainingLength ); /** * @brief Prints the appropriate message for the PUBREL, PUBACK response code if logs @@ -486,7 +486,7 @@ static MQTTStatus_t deserializePublishProperties( MQTTPublishInfo_t * pPublishIn MQTTPropBuilder_t * pPropBuffer, uint8_t * pIndex, uint16_t topicAliasMax, - size_t remainingLength ); + uint32_t remainingLength ); /** * @brief Prints and validates the appropriate message for the Disconnect response code if logs @@ -651,7 +651,7 @@ static MQTTStatus_t validateReasonCodeForAck( uint8_t ackPacketType, /*-----------------------------------------------------------*/ -static size_t remainingLengthEncodedSize( size_t length ) +static size_t remainingLengthEncodedSize( uint32_t length ) { size_t encodedSize; @@ -689,18 +689,19 @@ static size_t remainingLengthEncodedSize( size_t length ) /*-----------------------------------------------------------*/ static MQTTStatus_t calculatePublishPacketSize( const MQTTPublishInfo_t * pPublishInfo, - size_t * pRemainingLength, - size_t * pPacketSize, + uint32_t * pRemainingLength, + uint32_t * pPacketSize, uint32_t maxPacketSize, - size_t publishPropertyLength ) + uint32_t publishPropertyLength ) { MQTTStatus_t status = MQTTSuccess; - size_t packetSize = 0, propertyAndPayloadLimit = 0; - + uint32_t packetSize = 0; + uint32_t propertyAndPayloadLimit = 0; assert( pPublishInfo != NULL ); assert( pRemainingLength != NULL ); assert( pPacketSize != NULL ); + assert( !CHECK_SIZE_T_OVERFLOWS_16BIT( pPublishInfo->topicNameLength ) ); /* The variable header of a PUBLISH packet always contains the topic name. * The first 2 bytes of UTF-8 string contains length of the string. @@ -848,7 +849,7 @@ static MQTTStatus_t deserializePubAcks( const MQTTPacketInfo_t * pAck, /*-----------------------------------------------------------*/ MQTTStatus_t MQTT_SerializePublishHeaderWithoutTopic( const MQTTPublishInfo_t * pPublishInfo, - size_t remainingLength, + uint32_t remainingLength, uint8_t * pBuffer, size_t * headerSize ) { @@ -940,7 +941,7 @@ MQTTStatus_t MQTT_SerializePublishHeaderWithoutTopic( const MQTTPublishInfo_t * static void serializePublishCommon( const MQTTPublishInfo_t * pPublishInfo, const MQTTPropBuilder_t * pPublishProperties, - size_t remainingLength, + uint32_t remainingLength, uint16_t packetIdentifier, const MQTTFixedBuffer_t * pFixedBuffer, bool serializePayload ) @@ -957,6 +958,8 @@ static void serializePublishCommon( const MQTTPublishInfo_t * pPublishInfo, assert( ( pPublishInfo->qos == MQTTQoS0 ) || ( packetIdentifier != 0U ) ); /* Duplicate flag should be set only for Qos 1 or Qos 2. */ assert( ( pPublishInfo->dup != true ) || ( pPublishInfo->qos != MQTTQoS0 ) ); + /* The topic name length must fit in 16-bits. */ + assert( !CHECK_SIZE_T_OVERFLOWS_16BIT( pPublishInfo->topicNameLength ) ); /* Get the start address of the buffer. */ pIndex = pFixedBuffer->pBuffer; @@ -1099,7 +1102,7 @@ static MQTTStatus_t processRemainingLength( const uint8_t * pBuffer, const size_t * pIndex, MQTTPacketInfo_t * pIncomingPacket ) { - size_t remainingLength = 0; + uint32_t remainingLength = 0; size_t multiplier = 1; size_t bytesDecoded = 0; size_t expectedSize = 0; @@ -1209,9 +1212,9 @@ static bool incomingPacketValid( uint8_t packetType ) /*-----------------------------------------------------------*/ -static MQTTStatus_t checkPublishRemainingLength( size_t remainingLength, +static MQTTStatus_t checkPublishRemainingLength( uint32_t remainingLength, MQTTQoS_t qos, - size_t qos0Minimum ) + uint32_t qos0Minimum ) { MQTTStatus_t status = MQTTSuccess; @@ -1583,13 +1586,14 @@ static MQTTStatus_t deserializeConnack( MQTTConnectionProperties_t * pConnackPro static MQTTStatus_t calculateSubscriptionPacketSize( const MQTTSubscribeInfo_t * pSubscriptionList, size_t subscriptionCount, - size_t * pRemainingLength, - size_t * pPacketSize, - size_t subscribePropLen, + uint32_t * pRemainingLength, + uint32_t * pPacketSize, + uint32_t subscribePropLen, uint32_t maxPacketSize, MQTTSubscriptionType_t subscriptionType ) { - size_t packetSize = 0U, i = 0U; + uint32_t packetSize = 0U; + size_t i; MQTTStatus_t status = MQTTSuccess; assert( pSubscriptionList != NULL ); @@ -1605,6 +1609,13 @@ static MQTTStatus_t calculateSubscriptionPacketSize( const MQTTSubscribeInfo_t * for( i = 0; i < subscriptionCount; i++ ) { + if( CHECK_SIZE_T_OVERFLOWS_16BIT( pSubscriptionList[ i ].topicFilterLength ) ) + { + LogError( ( "Topic filter length must be less than 65536. Length is %" PRIu32, ( uint32_t ) pSubscriptionList[ i ].topicFilterLength ) ); + status = MQTTBadParameter; + break; + } + packetSize += pSubscriptionList[ i ].topicFilterLength + sizeof( uint16_t ); if( subscriptionType == MQTT_TYPE_SUBSCRIBE ) @@ -1616,7 +1627,7 @@ static MQTTStatus_t calculateSubscriptionPacketSize( const MQTTSubscribeInfo_t * /* At this point, the "Remaining length" has been calculated. Return error * if the "Remaining length" exceeds what is allowed by MQTT 5. Otherwise, * set the output parameter. */ - if( packetSize > MQTT_MAX_REMAINING_LENGTH ) + if( ( status == MQTTSuccess ) && ( packetSize > MQTT_MAX_REMAINING_LENGTH ) ) { LogError( ( "Subscribe packet size %lu exceeds %d. " "Packet size cannot be greater than %d.", @@ -1637,12 +1648,12 @@ static MQTTStatus_t calculateSubscriptionPacketSize( const MQTTSubscribeInfo_t * */ packetSize += 1U + variableLengthEncodedSize( packetSize ); *pPacketSize = packetSize; - } - if( packetSize > maxPacketSize ) - { - LogError( ( "Packet size is greater than the allowed maximum packet size." ) ); - status = MQTTBadParameter; + if( packetSize > maxPacketSize ) + { + LogError( ( "Packet size is greater than the allowed maximum packet size." ) ); + status = MQTTBadParameter; + } } LogDebug( ( "%s packet remaining length=%lu and packet size=%lu.", @@ -1746,7 +1757,7 @@ static MQTTStatus_t deserializeSubUnsubAck( const MQTTPacketInfo_t * incomingPac { MQTTStatus_t status = MQTTSuccess; uint8_t * pIndex = NULL; - size_t remainingLength = 0U; + uint32_t remainingLength = 0U; size_t statusTotalBytes = 0U; const uint8_t * pStatusStart; size_t propertyLength = 0U; @@ -1807,7 +1818,7 @@ static MQTTStatus_t deserializeSubUnsubAck( const MQTTPacketInfo_t * incomingPac static MQTTStatus_t validateSubscriptionSerializeParams( const MQTTSubscribeInfo_t * pSubscriptionList, size_t subscriptionCount, uint16_t packetId, - size_t remainingLength, + uint32_t remainingLength, const MQTTFixedBuffer_t * pFixedBuffer ) { MQTTStatus_t status = MQTTSuccess; @@ -2054,7 +2065,7 @@ static MQTTStatus_t deserializeConnackProperties( MQTTConnectionProperties_t * p { uint8_t propertyId = *pVariableHeader; const char * data; - uint16_t dataLength; + size_t dataLength; pVariableHeader = &pVariableHeader[ 1 ]; propertyLength -= sizeof( uint8_t ); @@ -2218,7 +2229,7 @@ static MQTTStatus_t deserializeConnackProperties( MQTTConnectionProperties_t * p { /* Proper uses for the reason string in the Client would include using this information * in an exception thrown by the Client code, or writing this string to a log. */ - LogInfo( ( "Reason string from server: %.*s", dataLength, data ) ); + LogInfo( ( "Reason string from server: %.*s", ( int ) dataLength, data ) ); if( pPropBuffer != NULL ) { @@ -2231,7 +2242,7 @@ static MQTTStatus_t deserializeConnackProperties( MQTTConnectionProperties_t * p case MQTT_USER_PROPERTY_ID: { const char * key, * value; - uint16_t keyLength, valueLength; + size_t keyLength, valueLength; status = decodeUserProp( &key, &keyLength, &value, &valueLength, &propertyLength, &pVariableHeader ); if( status == MQTTSuccess ) @@ -2353,7 +2364,7 @@ static MQTTStatus_t deserializeConnackProperties( MQTTConnectionProperties_t * p } else { - LogDebug( ( "Response information: %.*s", dataLength, data ) ); + LogDebug( ( "Response information: %.*s", ( int ) dataLength, data ) ); if( pPropBuffer != NULL ) { @@ -2369,7 +2380,7 @@ static MQTTStatus_t deserializeConnackProperties( MQTTConnectionProperties_t * p if( status == MQTTSuccess ) { - LogDebug( ( "Server reference: %.*s", dataLength, data ) ); + LogDebug( ( "Server reference: %.*s", ( int ) dataLength, data ) ); if( pPropBuffer != NULL ) { @@ -2384,7 +2395,7 @@ static MQTTStatus_t deserializeConnackProperties( MQTTConnectionProperties_t * p if( status == MQTTSuccess ) { - LogDebug( ( "Authentication method received: %.*s", dataLength, data ) ); + LogDebug( ( "Authentication method received: %.*s", ( int ) dataLength, data ) ); if( pPropBuffer != NULL ) { @@ -2401,7 +2412,7 @@ static MQTTStatus_t deserializeConnackProperties( MQTTConnectionProperties_t * p if( status == MQTTSuccess ) { - LogDebug( ( "Auth data received: %.*s", dataLength, data ) ); + LogDebug( ( "Auth data received: %.*s", ( int ) dataLength, data ) ); if( pPropBuffer != NULL ) { @@ -2494,13 +2505,13 @@ static MQTTStatus_t logAckResponse( MQTTSuccessFailReasonCode_t reasonCode, static MQTTStatus_t deserializeSubUnsubAckProperties( MQTTPropBuilder_t * pPropBuffer, uint8_t * pIndex, size_t * pSubackPropertyLength, - size_t remainingLength ) + uint32_t remainingLength ) { MQTTStatus_t status = MQTTSuccess; uint32_t propertyLength = 0U; uint8_t * pLocalIndex = pIndex; const char * pReasonString; - uint16_t reasonStringLength; + size_t reasonStringLength; bool reasonString = false; status = decodeVariableLength( pLocalIndex, remainingLength - 2U, &propertyLength ); @@ -2543,9 +2554,9 @@ static MQTTStatus_t deserializeSubUnsubAckProperties( MQTTPropBuilder_t * pPropB case MQTT_USER_PROPERTY_ID: { const char * propertyKey; - uint16_t propertyKeyLen; + size_t propertyKeyLen; const char * propertyValue; - uint16_t propertyValueLen; + size_t propertyValueLen; status = decodeUserProp( &propertyKey, &propertyKeyLen, &propertyValue, &propertyValueLen, &propertyLength, &pLocalIndex ); } @@ -2576,6 +2587,14 @@ static void serializeConnectPacket( const MQTTConnectInfo_t * pConnectInfo, assert( pConnectInfo != NULL ); assert( pFixedBuffer != NULL ); assert( pFixedBuffer->pBuffer != NULL ); + assert( !CHECK_SIZE_T_OVERFLOWS_16BIT( pConnectInfo->clientIdentifierLength ) ); + assert( !CHECK_SIZE_T_OVERFLOWS_16BIT( pConnectInfo->userNameLength ) ); + assert( !CHECK_SIZE_T_OVERFLOWS_16BIT( pConnectInfo->passwordLength ) ); + + if( pWillInfo != NULL ) + { + assert( !CHECK_SIZE_T_OVERFLOWS_16BIT( pWillInfo->topicNameLength ) ); + } pIndex = pFixedBuffer->pBuffer; @@ -2655,13 +2674,13 @@ static MQTTStatus_t deserializePublishProperties( MQTTPublishInfo_t * pPublishIn MQTTPropBuilder_t * pPropBuffer, uint8_t * pIndex, uint16_t topicAliasMax, - size_t remainingLength ) + uint32_t remainingLength ) { MQTTStatus_t status = MQTTSuccess; uint32_t propertyLength = 0U; uint8_t * pLocalIndex = pIndex; uint32_t subscriptionId; - size_t remainingLengthForProperties; + uint32_t remainingLengthForProperties; bool contentType = false; bool messageExpiryInterval = false; bool responseTopic = false; @@ -2670,6 +2689,8 @@ static MQTTStatus_t deserializePublishProperties( MQTTPublishInfo_t * pPublishIn bool correlationData = false; uint16_t topicAliasVal; + assert( !CHECK_SIZE_T_OVERFLOWS_16BIT( pPublishInfo->topicNameLength ) ); + /* Decode Property Length. */ remainingLengthForProperties = remainingLength; remainingLengthForProperties -= pPublishInfo->topicNameLength + sizeof( uint16_t ); @@ -2741,7 +2762,7 @@ static MQTTStatus_t deserializePublishProperties( MQTTPublishInfo_t * pPublishIn case MQTT_RESPONSE_TOPIC_ID: { const char * pProperty; - uint16_t length; + size_t length; status = decodeUtf8( &pProperty, &length, &propertyLength, &responseTopic, &pLocalIndex ); } break; @@ -2749,7 +2770,7 @@ static MQTTStatus_t deserializePublishProperties( MQTTPublishInfo_t * pPublishIn case MQTT_CORRELATION_DATA_ID: { const char * pProperty; - uint16_t length; + size_t length; status = decodeUtf8( &pProperty, &length, &propertyLength, &correlationData, &pLocalIndex ); } break; @@ -2764,7 +2785,7 @@ static MQTTStatus_t deserializePublishProperties( MQTTPublishInfo_t * pPublishIn case MQTT_CONTENT_TYPE_ID: { const char * pProperty; - uint16_t length; + size_t length; status = decodeUtf8( &pProperty, &length, &propertyLength, &contentType, &pLocalIndex ); } break; @@ -2783,9 +2804,9 @@ static MQTTStatus_t deserializePublishProperties( MQTTPublishInfo_t * pPublishIn case MQTT_USER_PROPERTY_ID: { const char * pPropertyKey; - uint16_t propertyKeyLen; + size_t propertyKeyLen; const char * pPropertyValue; - uint16_t propertyValueLen; + size_t propertyValueLen; status = decodeUserProp( &pPropertyKey, &propertyKeyLen, &pPropertyValue, @@ -2894,7 +2915,7 @@ MQTTStatus_t updateContextWithConnectProps( const MQTTPropBuilder_t * pPropBuild case MQTT_AUTH_METHOD_ID: { const char * data; - uint16_t dataLength; + size_t dataLength; status = decodeUtf8( &data, &dataLength, &propertyLength, &used, &pIndex ); } break; @@ -2902,7 +2923,7 @@ MQTTStatus_t updateContextWithConnectProps( const MQTTPropBuilder_t * pPropBuild case MQTT_USER_PROPERTY_ID: { const char * key, * value; - uint16_t keyLength, valueLength; + size_t keyLength, valueLength; status = decodeUserProp( &key, &keyLength, &value, @@ -2956,6 +2977,21 @@ MQTTStatus_t MQTT_GetConnectPacketSize( const MQTTConnectInfo_t * pConnectInfo, LogError( ( "Client ID length and value mismatch." ) ); status = MQTTBadParameter; } + else if( CHECK_SIZE_T_OVERFLOWS_16BIT( pConnectInfo->clientIdentifierLength ) ) + { + LogError( ( "Client ID length must be less than 65536 according to MQTT spec." ) ); + status = MQTTBadParameter; + } + else if( CHECK_SIZE_T_OVERFLOWS_16BIT( pConnectInfo->userNameLength ) ) + { + LogError( ( "User name length must be less than 65536 according to MQTT spec." ) ); + status = MQTTBadParameter; + } + else if( CHECK_SIZE_T_OVERFLOWS_16BIT( pConnectInfo->passwordLength ) ) + { + LogError( ( "Password length must be less than 65536 according to MQTT spec." ) ); + status = MQTTBadParameter; + } else if( ( pWillInfo != NULL ) && ( pWillInfo->payloadLength > ( size_t ) UINT16_MAX ) ) { /* The MQTTPublishInfo_t is reused for the will message. The payload @@ -2967,19 +3003,48 @@ MQTTStatus_t MQTT_GetConnectPacketSize( const MQTTConnectInfo_t * pConnectInfo, ( unsigned long ) pWillInfo->payloadLength ) ); status = MQTTBadParameter; } + else if( ( pWillInfo != NULL ) && CHECK_SIZE_T_OVERFLOWS_16BIT( pWillInfo->topicNameLength ) ) + { + LogError( ( "Will Topic name length must be less than 65536 according to MQTT spec." ) ); + status = MQTTBadParameter; + } else { /* Do Nothing. */ } - if( ( pConnectProperties != NULL ) && ( pConnectProperties->pBuffer != NULL ) ) + if( ( status == MQTTSuccess ) && ( pConnectProperties != NULL ) && ( pConnectProperties->pBuffer != NULL ) ) { - propertyLength = pConnectProperties->currentIndex; + /* The value must fit in a 32-bit variable all the while being small enough to + * be properly encoded in a variable integer format. */ + if( CHECK_SIZE_T_OVERFLOWS_32BIT( pConnectProperties->currentIndex ) || + ( pConnectProperties->currentIndex > MQTT_MAX_REMAINING_LENGTH ) ) + { + LogError( ( "Connect properties must be less than 268435456 " + "to be able to fit in a MQTT packet." ) ); + status = MQTTBadParameter; + } + else + { + propertyLength = pConnectProperties->currentIndex; + } } - if( ( pWillProperties != NULL ) && ( pWillProperties->pBuffer != NULL ) ) + if( ( status == MQTTSuccess ) && ( pWillProperties != NULL ) && ( pWillProperties->pBuffer != NULL ) ) { - willPropertyLength = pWillProperties->currentIndex; + /* The value must fit in a 32-bit variable all the while being small enough to + * be properly encoded in a variable integer format. */ + if( CHECK_SIZE_T_OVERFLOWS_32BIT( pWillProperties->currentIndex ) || + ( pWillProperties->currentIndex > MQTT_MAX_REMAINING_LENGTH ) ) + { + LogError( ( "Will properties must be less than 268435456 " + "to be able to fit in a MQTT packet." ) ); + status = MQTTBadParameter; + } + else + { + willPropertyLength = pWillProperties->currentIndex; + } } if( status == MQTTSuccess ) @@ -3050,7 +3115,7 @@ MQTTStatus_t MQTT_GetConnectPacketSize( const MQTTConnectInfo_t * pConnectInfo, static MQTTStatus_t decodePubAckProperties( MQTTPropBuilder_t * pPropBuffer, uint8_t * pIndex, - size_t remainingLength ) + uint32_t remainingLength ) { uint32_t propertyLength = 0U; MQTTStatus_t status = MQTTSuccess; @@ -3095,7 +3160,7 @@ static MQTTStatus_t decodePubAckProperties( MQTTPropBuilder_t * pPropBuffer, case MQTT_REASON_STRING_ID: { const char * pProperty; - uint16_t length; + size_t length; status = decodeUtf8( &pProperty, &length, &propertyLength, &reasonString, &pLocalIndex ); break; } @@ -3103,9 +3168,9 @@ static MQTTStatus_t decodePubAckProperties( MQTTPropBuilder_t * pPropBuffer, case MQTT_USER_PROPERTY_ID: { const char * pPropertyKey; - uint16_t propertyKeyLen; + size_t propertyKeyLen; const char * pPropertyValue; - uint16_t propertyValueLen; + size_t propertyValueLen; status = decodeUserProp( &pPropertyKey, &propertyKeyLen, &pPropertyValue, @@ -3231,6 +3296,26 @@ MQTTStatus_t MQTT_SerializeConnect( const MQTTConnectInfo_t * pConnectInfo, LogError( ( "pWillInfo->pTopicName cannot be NULL if Will is present." ) ); status = MQTTBadParameter; } + else if( CHECK_SIZE_T_OVERFLOWS_16BIT( pConnectInfo->clientIdentifierLength ) ) + { + LogError( ( "clientIdentifierLength must be less than 65536 to fit in 16-bits." ) ); + status = MQTTBadParameter; + } + else if( CHECK_SIZE_T_OVERFLOWS_16BIT( pConnectInfo->userNameLength ) ) + { + LogError( ( "userNameLength must be less than 65536 to fit in 16-bits." ) ); + status = MQTTBadParameter; + } + else if( CHECK_SIZE_T_OVERFLOWS_16BIT( pConnectInfo->passwordLength ) ) + { + LogError( ( "passwordLength must be less than 65536 to fit in 16-bits." ) ); + status = MQTTBadParameter; + } + else if( ( pWillInfo != NULL ) && CHECK_SIZE_T_OVERFLOWS_16BIT( pWillInfo->topicNameLength ) ) + { + LogError( ( "topicNameLength must be less than 65536 to fit in 16-bits." ) ); + status = MQTTBadParameter; + } else { /* Calculate CONNECT packet size. Overflow in in this addition is not checked @@ -3266,12 +3351,12 @@ MQTTStatus_t MQTT_SerializeConnect( const MQTTConnectInfo_t * pConnectInfo, MQTTStatus_t MQTT_GetSubscribePacketSize( const MQTTSubscribeInfo_t * pSubscriptionList, size_t subscriptionCount, const MQTTPropBuilder_t * pSubscribeProperties, - size_t * pRemainingLength, - size_t * pPacketSize, + uint32_t * pRemainingLength, + uint32_t * pPacketSize, uint32_t maxPacketSize ) { MQTTStatus_t status = MQTTSuccess; - size_t propertyLength = 0U; + uint32_t propertyLength = 0U; if( pSubscriptionList == NULL ) { @@ -3292,12 +3377,27 @@ MQTTStatus_t MQTT_GetSubscribePacketSize( const MQTTSubscribeInfo_t * pSubscript { if( ( pSubscribeProperties != NULL ) && ( pSubscribeProperties->pBuffer != NULL ) ) { - propertyLength = pSubscribeProperties->currentIndex; + /* The value must fit in a 32-bit variable all the while being small enough to + * be properly encoded in a variable integer format. */ + if( CHECK_SIZE_T_OVERFLOWS_32BIT( pSubscribeProperties->currentIndex ) || + ( pSubscribeProperties->currentIndex > MQTT_MAX_REMAINING_LENGTH ) ) + { + LogError( ( "Subscription properties must be less than 268435456 " + "to be able to fit in a MQTT packet." ) ); + status = MQTTBadParameter; + } + else + { + propertyLength = pSubscribeProperties->currentIndex; + } } - status = calculateSubscriptionPacketSize( pSubscriptionList, subscriptionCount, - pRemainingLength, pPacketSize, propertyLength, - maxPacketSize, MQTT_TYPE_SUBSCRIBE ); + if( status == MQTTSuccess ) + { + status = calculateSubscriptionPacketSize( pSubscriptionList, subscriptionCount, + pRemainingLength, pPacketSize, propertyLength, + maxPacketSize, MQTT_TYPE_SUBSCRIBE ); + } } return status; @@ -3309,7 +3409,7 @@ MQTTStatus_t MQTT_SerializeSubscribe( const MQTTSubscribeInfo_t * pSubscriptionL size_t subscriptionCount, const MQTTPropBuilder_t * pSubscribeProperties, uint16_t packetId, - size_t remainingLength, + uint32_t remainingLength, const MQTTFixedBuffer_t * pFixedBuffer ) { size_t i = 0; @@ -3420,17 +3520,12 @@ MQTTStatus_t MQTT_SerializeSubscribe( const MQTTSubscribeInfo_t * pSubscriptionL MQTTStatus_t MQTT_GetUnsubscribePacketSize( const MQTTSubscribeInfo_t * pSubscriptionList, size_t subscriptionCount, const MQTTPropBuilder_t * pUnsubscribeProperties, - size_t * pRemainingLength, - size_t * pPacketSize, + uint32_t * pRemainingLength, + uint32_t * pPacketSize, uint32_t maxPacketSize ) { MQTTStatus_t status = MQTTSuccess; - size_t propertyLength = 0U; - - if( ( pUnsubscribeProperties != NULL ) && ( pUnsubscribeProperties->pBuffer != NULL ) ) - { - propertyLength = pUnsubscribeProperties->currentIndex; - } + uint32_t propertyLength = 0U; /* Validate parameters. */ if( ( pSubscriptionList == NULL ) || ( pRemainingLength == NULL ) || @@ -3450,14 +3545,34 @@ MQTTStatus_t MQTT_GetUnsubscribePacketSize( const MQTTSubscribeInfo_t * pSubscri } else { - /* Calculate the MQTT UNSUBSCRIBE packet size. */ - status = calculateSubscriptionPacketSize( pSubscriptionList, - subscriptionCount, - pRemainingLength, - pPacketSize, - propertyLength, - maxPacketSize, - MQTT_TYPE_UNSUBSCRIBE ); + if( ( pUnsubscribeProperties != NULL ) && ( pUnsubscribeProperties->pBuffer != NULL ) ) + { + /* The value must fit in a 32-bit variable all the while being small enough to + * be properly encoded in a variable integer format. */ + if( CHECK_SIZE_T_OVERFLOWS_32BIT( pUnsubscribeProperties->currentIndex ) || + ( pUnsubscribeProperties->currentIndex > MQTT_MAX_REMAINING_LENGTH ) ) + { + LogError( ( "Un-Subscription properties must be less than 268435456 " + "to be able to fit in a MQTT packet." ) ); + status = MQTTBadParameter; + } + else + { + propertyLength = pUnsubscribeProperties->currentIndex; + } + } + + if( status == MQTTSuccess ) + { + /* Calculate the MQTT UNSUBSCRIBE packet size. */ + status = calculateSubscriptionPacketSize( pSubscriptionList, + subscriptionCount, + pRemainingLength, + pPacketSize, + propertyLength, + maxPacketSize, + MQTT_TYPE_UNSUBSCRIBE ); + } } return status; @@ -3477,6 +3592,13 @@ MQTTStatus_t MQTT_ValidateUnsubscribeProperties( const MQTTPropBuilder_t * pProp propertyLength = pPropertyBuilder->currentIndex; pIndex = pPropertyBuilder->pBuffer; } + else if( ( pPropertyBuilder != NULL ) && + ( ( CHECK_SIZE_T_OVERFLOWS_32BIT( pPropertyBuilder->currentIndex ) ) || + ( pPropertyBuilder->currentIndex >= MQTT_REMAINING_LENGTH_INVALID ) ) ) + { + LogError( ( "Property length cannot have more than %" PRIu32 " bytes", MQTT_REMAINING_LENGTH_INVALID ) ); + status = MQTTBadParameter; + } while( ( propertyLength > 0U ) && ( status == MQTTSuccess ) ) { @@ -3489,7 +3611,7 @@ MQTTStatus_t MQTT_ValidateUnsubscribeProperties( const MQTTPropBuilder_t * pProp case MQTT_USER_PROPERTY_ID: { const char * key, * value; - uint16_t keyLength, valueLength; + size_t keyLength, valueLength; status = decodeUserProp( &key, &keyLength, &value, &valueLength, &propertyLength, &pIndex ); if( status == MQTTSuccess ) @@ -3516,7 +3638,7 @@ MQTTStatus_t MQTT_SerializeUnsubscribe( const MQTTSubscribeInfo_t * pSubscriptio size_t subscriptionCount, const MQTTPropBuilder_t * pUnsubscribeProperties, uint16_t packetId, - size_t remainingLength, + uint32_t remainingLength, const MQTTFixedBuffer_t * pFixedBuffer ) { MQTTStatus_t status = MQTTSuccess; @@ -3571,16 +3693,28 @@ MQTTStatus_t MQTT_SerializeUnsubscribe( const MQTTSubscribeInfo_t * pSubscriptio MQTTStatus_t MQTT_GetPublishPacketSize( const MQTTPublishInfo_t * pPublishInfo, const MQTTPropBuilder_t * pPublishProperties, - size_t * pRemainingLength, - size_t * pPacketSize, + uint32_t * pRemainingLength, + uint32_t * pPacketSize, uint32_t maxPacketSize ) { MQTTStatus_t status = MQTTSuccess; - size_t propertyLength = 0U; + uint32_t propertyLength = 0U; if( ( pPublishProperties != NULL ) && ( pPublishProperties->pBuffer != NULL ) ) { - propertyLength = pPublishProperties->currentIndex; + /* The value must fit in a 32-bit variable all the while being small enough to + * be properly encoded in a variable integer format. */ + if( CHECK_SIZE_T_OVERFLOWS_32BIT( pPublishProperties->currentIndex ) || + ( pPublishProperties->currentIndex > MQTT_MAX_REMAINING_LENGTH ) ) + { + LogError( ( "Publish properties must be less than 268435456 " + "to be able to fit in a MQTT packet." ) ); + status = MQTTBadParameter; + } + else + { + propertyLength = pPublishProperties->currentIndex; + } } if( ( pPublishInfo == NULL ) || ( pRemainingLength == NULL ) || ( pPacketSize == NULL ) ) @@ -3592,6 +3726,11 @@ MQTTStatus_t MQTT_GetPublishPacketSize( const MQTTPublishInfo_t * pPublishInfo, ( void * ) pPacketSize ) ); status = MQTTBadParameter; } + else if( CHECK_SIZE_T_OVERFLOWS_16BIT( pPublishInfo->topicNameLength ) ) + { + LogError( ( "Topic name length must be smaller than 65535." ) ); + status = MQTTBadParameter; + } else { status = calculatePublishPacketSize( pPublishInfo, pRemainingLength, @@ -3606,7 +3745,7 @@ MQTTStatus_t MQTT_GetPublishPacketSize( const MQTTPublishInfo_t * pPublishInfo, MQTTStatus_t MQTT_SerializePublish( const MQTTPublishInfo_t * pPublishInfo, const MQTTPropBuilder_t * pPublishProperties, uint16_t packetId, - size_t remainingLength, + uint32_t remainingLength, const MQTTFixedBuffer_t * pFixedBuffer ) { MQTTStatus_t status = MQTTSuccess; @@ -3656,6 +3795,11 @@ MQTTStatus_t MQTT_SerializePublish( const MQTTPublishInfo_t * pPublishInfo, LogError( ( "Duplicate flag is set for PUBLISH with Qos 0." ) ); status = MQTTBadParameter; } + else if( CHECK_SIZE_T_OVERFLOWS_16BIT( pPublishInfo->topicNameLength ) ) + { + LogError( ( "topicNameLength must be less than 65535 to fit in 16-bits." ) ); + status = MQTTBadParameter; + } else { /* Length of serialized packet = First byte @@ -3693,7 +3837,7 @@ MQTTStatus_t MQTT_SerializePublish( const MQTTPublishInfo_t * pPublishInfo, MQTTStatus_t MQTT_SerializePublishHeader( const MQTTPublishInfo_t * pPublishInfo, const MQTTPropBuilder_t * pPublishProperties, uint16_t packetId, - size_t remainingLength, + uint32_t remainingLength, const MQTTFixedBuffer_t * pFixedBuffer, size_t * pHeaderSize ) { @@ -3724,6 +3868,11 @@ MQTTStatus_t MQTT_SerializePublishHeader( const MQTTPublishInfo_t * pPublishInfo ( unsigned short ) pPublishInfo->topicNameLength ) ); status = MQTTBadParameter; } + else if( CHECK_SIZE_T_OVERFLOWS_16BIT( pPublishInfo->topicNameLength ) ) + { + LogError( ( "topicNameLength must be less than 65535 to fit in 16-bits." ) ); + status = MQTTBadParameter; + } else if( ( pPublishInfo->qos != MQTTQoS0 ) && ( packetId == 0U ) ) { LogError( ( "Packet Id is 0 for publish with QoS=%hu.", @@ -3873,20 +4022,15 @@ MQTTStatus_t MQTT_SerializeAck( const MQTTFixedBuffer_t * pFixedBuffer, /*-----------------------------------------------------------*/ MQTTStatus_t MQTT_GetDisconnectPacketSize( const MQTTPropBuilder_t * pDisconnectProperties, - size_t * pRemainingLength, - size_t * pPacketSize, + uint32_t * pRemainingLength, + uint32_t * pPacketSize, uint32_t maxPacketSize, MQTTSuccessFailReasonCode_t * pReasonCode ) { MQTTStatus_t status = MQTTSuccess; - size_t length = 0U; - size_t packetSize = 0U; - size_t propertyLength = 0U; - - if( ( pDisconnectProperties != NULL ) && ( pDisconnectProperties->pBuffer != NULL ) ) - { - propertyLength = pDisconnectProperties->currentIndex; - } + uint32_t length = 0U; + uint32_t packetSize = 0U; + uint32_t propertyLength = 0U; /* Validate the arguments. */ if( ( pReasonCode == NULL ) && ( pDisconnectProperties != NULL ) ) @@ -3924,22 +4068,42 @@ MQTTStatus_t MQTT_GetDisconnectPacketSize( const MQTTPropBuilder_t * pDisconnect if( status == MQTTSuccess ) { - /* Validate the length. The sum of: - * Bytes required to encode the properties + - * Actual properties + - * Optional reason code (which is depicted by length) - * - * Must be less than the maximum allowed remaining length. - */ - if( ( propertyLength + variableLengthEncodedSize( propertyLength ) + length ) < MQTT_MAX_REMAINING_LENGTH ) + if( ( pDisconnectProperties != NULL ) && ( pDisconnectProperties->pBuffer != NULL ) ) { - length += variableLengthEncodedSize( propertyLength ) + propertyLength; - *pRemainingLength = length; + /* The value must fit in a 32-bit variable all the while being small enough to + * be properly encoded in a variable integer format. */ + if( CHECK_SIZE_T_OVERFLOWS_32BIT( pDisconnectProperties->currentIndex ) || + ( pDisconnectProperties->currentIndex > MQTT_MAX_REMAINING_LENGTH ) ) + { + LogError( ( "Disconnect properties must be less than 268435456 " + "to be able to fit in a MQTT packet." ) ); + status = MQTTBadParameter; + } + else + { + propertyLength = pDisconnectProperties->currentIndex; + } } - else + + if( status == MQTTSuccess ) { - LogError( ( "The properties + reason code cannot fit in MQTT_MAX_REMAINING_LENGTH bytes." ) ); - status = MQTTBadParameter; + /* Validate the length. The sum of: + * Bytes required to encode the properties + + * Actual properties + + * Optional reason code (which is depicted by length) + * + * Must be less than the maximum allowed remaining length. + */ + if( ( propertyLength + variableLengthEncodedSize( propertyLength ) + length ) < MQTT_MAX_REMAINING_LENGTH ) + { + length += variableLengthEncodedSize( propertyLength ) + propertyLength; + *pRemainingLength = length; + } + else + { + LogError( ( "The properties + reason code cannot fit in MQTT_MAX_REMAINING_LENGTH bytes." ) ); + status = MQTTBadParameter; + } } } @@ -3970,7 +4134,7 @@ MQTTStatus_t MQTT_GetDisconnectPacketSize( const MQTTPropBuilder_t * pDisconnect MQTTStatus_t MQTT_SerializeDisconnect( const MQTTPropBuilder_t * pDisconnectProperties, MQTTSuccessFailReasonCode_t * pReasonCode, - size_t remainingLength, + uint32_t remainingLength, const MQTTFixedBuffer_t * pFixedBuffer ) { MQTTStatus_t status = MQTTSuccess; @@ -4040,7 +4204,7 @@ MQTTStatus_t MQTT_SerializeDisconnect( const MQTTPropBuilder_t * pDisconnectProp /*-----------------------------------------------------------*/ -MQTTStatus_t MQTT_GetPingreqPacketSize( size_t * pPacketSize ) +MQTTStatus_t MQTT_GetPingreqPacketSize( uint32_t * pPacketSize ) { MQTTStatus_t status = MQTTSuccess; @@ -4555,8 +4719,10 @@ MQTTStatus_t MQTT_ValidateWillProperties( const MQTTPropBuilder_t * pPropertyBui { status = MQTTBadParameter; } - else if( pPropertyBuilder->currentIndex >= MQTT_REMAINING_LENGTH_INVALID ) + else if( ( CHECK_SIZE_T_OVERFLOWS_32BIT( pPropertyBuilder->currentIndex ) ) || + ( pPropertyBuilder->currentIndex >= MQTT_REMAINING_LENGTH_INVALID ) ) { + LogError( ( "Property length cannot have more than %" PRIu32 " bytes", MQTT_REMAINING_LENGTH_INVALID ) ); status = MQTTBadParameter; } else @@ -4570,7 +4736,7 @@ MQTTStatus_t MQTT_ValidateWillProperties( const MQTTPropBuilder_t * pPropertyBui uint8_t propertyId = *pIndex; bool used = false; const char * data; - uint16_t dataLength; + size_t dataLength; pIndex = &pIndex[ 1 ]; propertyLength -= sizeof( uint8_t ); @@ -4681,7 +4847,7 @@ MQTTStatus_t MQTT_ValidateWillProperties( const MQTTPropBuilder_t * pPropertyBui case MQTT_USER_PROPERTY_ID: { const char * key, * value; - uint16_t keyLength, valueLength; + size_t keyLength, valueLength; status = decodeUserProp( &key, &keyLength, &value, @@ -4716,6 +4882,12 @@ MQTTStatus_t MQTT_ValidateConnectProperties( const MQTTPropBuilder_t * pProperty { status = MQTTBadParameter; } + else if( ( CHECK_SIZE_T_OVERFLOWS_32BIT( pPropertyBuilder->currentIndex ) ) || + ( pPropertyBuilder->currentIndex >= MQTT_REMAINING_LENGTH_INVALID ) ) + { + LogError( ( "Property length cannot have more than %" PRIu32 " bytes", MQTT_REMAINING_LENGTH_INVALID ) ); + status = MQTTBadParameter; + } else { propertyLength = pPropertyBuilder->currentIndex; @@ -4728,7 +4900,7 @@ MQTTStatus_t MQTT_ValidateConnectProperties( const MQTTPropBuilder_t * pProperty uint8_t propertyId = *pIndex; bool used = false; const char * data; - uint16_t dataLength; + size_t dataLength; pIndex = &pIndex[ 1 ]; propertyLength -= sizeof( uint8_t ); @@ -4902,7 +5074,7 @@ MQTTStatus_t MQTT_ValidateConnectProperties( const MQTTPropBuilder_t * pProperty case MQTT_USER_PROPERTY_ID: { const char * key, * value; - uint16_t keyLength, valueLength; + size_t keyLength, valueLength; status = decodeUserProp( &key, &keyLength, &value, @@ -4947,6 +5119,12 @@ MQTTStatus_t MQTT_ValidateSubscribeProperties( bool isSubscriptionIdAvailable, { status = MQTTBadParameter; } + else if( ( CHECK_SIZE_T_OVERFLOWS_32BIT( propBuilder->currentIndex ) ) || + ( propBuilder->currentIndex >= MQTT_REMAINING_LENGTH_INVALID ) ) + { + LogError( ( "Property length cannot have more than %" PRIu32 " bytes", MQTT_REMAINING_LENGTH_INVALID ) ); + status = MQTTBadParameter; + } else { propertyLength = propBuilder->currentIndex; @@ -5001,7 +5179,7 @@ MQTTStatus_t MQTT_ValidateSubscribeProperties( bool isSubscriptionIdAvailable, case MQTT_USER_PROPERTY_ID: { const char * key, * value; - uint16_t keyLength, valueLength; + size_t keyLength, valueLength; status = decodeUserProp( &key, &keyLength, &value, &valueLength, &propertyLength, &pLocalIndex ); if( status == MQTTSuccess ) @@ -5043,6 +5221,12 @@ MQTTStatus_t MQTT_ValidatePublishProperties( uint16_t serverTopicAliasMax, LogError( ( "Topic Alias is NULL." ) ); status = MQTTBadParameter; } + else if( ( CHECK_SIZE_T_OVERFLOWS_32BIT( propBuilder->currentIndex ) ) || + ( propBuilder->currentIndex >= MQTT_REMAINING_LENGTH_INVALID ) ) + { + LogError( ( "Property length cannot have more than %" PRIu32 " bytes", MQTT_REMAINING_LENGTH_INVALID ) ); + status = MQTTBadParameter; + } else { propertyLength = propBuilder->currentIndex; @@ -5077,7 +5261,7 @@ MQTTStatus_t MQTT_ValidatePublishProperties( uint16_t serverTopicAliasMax, case MQTT_RESPONSE_TOPIC_ID: { const char * pProperty; - uint16_t length; + size_t length; status = decodeUtf8( &pProperty, &length, &propertyLength, &used, &pLocalIndex ); break; } @@ -5096,9 +5280,9 @@ MQTTStatus_t MQTT_ValidatePublishProperties( uint16_t serverTopicAliasMax, case MQTT_USER_PROPERTY_ID: { const char * pPropertyKey; - uint16_t propertyKeyLen; + size_t propertyKeyLen; const char * pPropertyValue; - uint16_t propertyValueLen; + size_t propertyValueLen; status = decodeUserProp( &pPropertyKey, &propertyKeyLen, &pPropertyValue, @@ -5161,6 +5345,11 @@ MQTTStatus_t MQTT_ValidatePublishParams( const MQTTPublishInfo_t * pPublishInfo, ( unsigned short ) pPublishInfo->topicNameLength ) ); status = MQTTBadParameter; } + else if( CHECK_SIZE_T_OVERFLOWS_16BIT( pPublishInfo->topicNameLength ) ) + { + LogError( ( "topicNameLength must be less than 65535 to fit in 16-bits." ) ); + status = MQTTBadParameter; + } else if( maxPacketSize == 0U ) { status = MQTTBadParameter; @@ -5182,7 +5371,15 @@ MQTTStatus_t MQTT_ValidatePublishAckProperties( const MQTTPropBuilder_t * pPrope uint8_t * pIndex = NULL; bool used = false; - if( ( pPropertyBuilder != NULL ) && ( pPropertyBuilder->pBuffer != NULL ) ) + if( ( pPropertyBuilder != NULL ) && + ( ( CHECK_SIZE_T_OVERFLOWS_32BIT( pPropertyBuilder->currentIndex ) ) || + ( pPropertyBuilder->currentIndex >= MQTT_REMAINING_LENGTH_INVALID ) ) ) + { + LogError( ( "Property length cannot have more than %" PRIu32 " bytes", MQTT_REMAINING_LENGTH_INVALID ) ); + status = MQTTBadParameter; + } + + if( ( status == MQTTSuccess ) && ( pPropertyBuilder != NULL ) && ( pPropertyBuilder->pBuffer != NULL ) ) { propertyLength = pPropertyBuilder->currentIndex; pIndex = pPropertyBuilder->pBuffer; @@ -5199,7 +5396,7 @@ MQTTStatus_t MQTT_ValidatePublishAckProperties( const MQTTPropBuilder_t * pPrope case MQTT_REASON_STRING_ID: { const char * pProperty; - uint16_t length; + size_t length; status = decodeUtf8( &pProperty, &length, &propertyLength, &used, &pIndex ); } break; @@ -5207,7 +5404,7 @@ MQTTStatus_t MQTT_ValidatePublishAckProperties( const MQTTPropBuilder_t * pPrope case MQTT_USER_PROPERTY_ID: { const char * key, * value; - uint16_t keyLength, valueLength; + size_t keyLength, valueLength; status = decodeUserProp( &key, &keyLength, &value, @@ -5228,29 +5425,37 @@ MQTTStatus_t MQTT_ValidatePublishAckProperties( const MQTTPropBuilder_t * pPrope /*-----------------------------------------------------------*/ -MQTTStatus_t MQTT_GetAckPacketSize( size_t * pRemainingLength, - size_t * pPacketSize, +MQTTStatus_t MQTT_GetAckPacketSize( uint32_t * pRemainingLength, + uint32_t * pPacketSize, uint32_t maxPacketSize, size_t ackPropertyLength ) { MQTTStatus_t status = MQTTSuccess; size_t length = 0U; - size_t propertyLength = 0U; - size_t packetSize = 0U; - - propertyLength = ackPropertyLength; + uint32_t propertyLength; + uint32_t packetSize = 0U; /* Validate the parameters. */ if( ( pRemainingLength == NULL ) || ( pPacketSize == NULL ) ) { + LogError( ( "pRemainingLength and pPacketSize cannot be NULL." ) ); status = MQTTBadParameter; } else if( maxPacketSize == 0U ) { + LogError( ( "maxPacketSize cannot be 0 as specified by MQTT spec." ) ); + status = MQTTBadParameter; + } + else if( CHECK_SIZE_T_OVERFLOWS_32BIT( ackPropertyLength ) || + ( ackPropertyLength > MQTT_MAX_REMAINING_LENGTH ) ) + { + LogError( ( "ackPropertyLength must be smaller than 268435455 to fit in MQTT packet." ) ); status = MQTTBadParameter; } else { + propertyLength = ackPropertyLength; + /* 1 byte Reason code + 2 byte Packet Identifier. */ length += 3U; @@ -5302,6 +5507,12 @@ MQTTStatus_t MQTT_ValidateDisconnectProperties( uint32_t connectSessionExpiry, LogError( ( "Arguments cannot be NULL : pPropertyBuilder=%p.", ( void * ) pPropertyBuilder ) ); status = MQTTBadParameter; } + else if( ( CHECK_SIZE_T_OVERFLOWS_32BIT( pPropertyBuilder->currentIndex ) ) || + ( pPropertyBuilder->currentIndex >= MQTT_REMAINING_LENGTH_INVALID ) ) + { + LogError( ( "Property length cannot have more than %" PRIu32 " bytes", MQTT_REMAINING_LENGTH_INVALID ) ); + status = MQTTBadParameter; + } else { propertyLength = pPropertyBuilder->currentIndex; @@ -5334,7 +5545,7 @@ MQTTStatus_t MQTT_ValidateDisconnectProperties( uint32_t connectSessionExpiry, case MQTT_REASON_STRING_ID: { const char * pProperty; - uint16_t length; + size_t length; status = decodeUtf8( &pProperty, &length, &propertyLength, &used, &pIndex ); } break; @@ -5342,7 +5553,7 @@ MQTTStatus_t MQTT_ValidateDisconnectProperties( uint32_t connectSessionExpiry, case MQTT_USER_PROPERTY_ID: { const char * key, * value; - uint16_t keyLength, valueLength; + size_t keyLength, valueLength; status = decodeUserProp( &key, &keyLength, &value, &valueLength, &propertyLength, &pIndex ); } break; @@ -5468,17 +5679,17 @@ static MQTTStatus_t validateIncomingDisconnectProperties( uint8_t * pIndex, MQTTStatus_t status = MQTTSuccess; uint8_t * pLocalIndex = pIndex; const char * pReasonString; - uint16_t reasonStringLength; + size_t reasonStringLength; const char * pServerRef; - uint16_t pServerRefLength; + size_t pServerRefLength; uint32_t propertyLength = disconnectPropertyLength; + bool reasonString = false; + bool serverRef = false; while( ( propertyLength > 0U ) && ( status == MQTTSuccess ) ) { /* Decode the property id. */ uint8_t propertyId = *pLocalIndex; - bool reasonString = false; - bool serverRef = false; pLocalIndex = &pLocalIndex[ 1 ]; propertyLength -= sizeof( uint8_t ); @@ -5492,7 +5703,7 @@ static MQTTStatus_t validateIncomingDisconnectProperties( uint8_t * pIndex, case MQTT_USER_PROPERTY_ID: { const char * key, * value; - uint16_t keyLength, valueLength; + size_t keyLength, valueLength; status = decodeUserProp( &key, &keyLength, &value, &valueLength, &propertyLength, &pLocalIndex ); } break; diff --git a/source/core_mqtt_serializer_private.c b/source/core_mqtt_serializer_private.c index f7ed298c..d7ec635b 100644 --- a/source/core_mqtt_serializer_private.c +++ b/source/core_mqtt_serializer_private.c @@ -25,6 +25,11 @@ /** * @file core_mqtt_serializer_private.c * @brief Implements private functions used by serializer and deserializer. + * DO NOT use these functions in your application. + * + * @note These functions should not be called by the application or relied upon + * since their implementation can change. These are for internal use by the + * library only. */ #include #include @@ -114,17 +119,17 @@ uint8_t * encodeString( uint8_t * pDestination, /*-----------------------------------------------------------*/ MQTTStatus_t decodeUserProp( const char ** pPropertyKey, - uint16_t * pPropertyKeyLen, + size_t * pPropertyKeyLen, const char ** pPropertyValue, - uint16_t * pPropertyValueLen, + size_t * pPropertyValueLen, uint32_t * pPropertyLength, uint8_t ** pIndex ) { MQTTStatus_t status = MQTTSuccess; const char * pKey = NULL; const char * pValue = NULL; - uint16_t keyLength = 0U; - uint16_t valueLength = 0U; + size_t keyLength = 0U; + size_t valueLength = 0U; bool used = false; assert( pIndex != NULL ); @@ -275,7 +280,7 @@ MQTTStatus_t decodeUint8t( uint8_t * pProperty, /*-----------------------------------------------------------*/ MQTTStatus_t decodeUtf8( const char ** pProperty, - uint16_t * pLength, + size_t * pLength, uint32_t * pPropertyLength, bool * pUsed, uint8_t ** pIndex ) @@ -434,7 +439,7 @@ uint8_t * encodeVariableLength( uint8_t * pDestination, uint8_t * serializeAckFixed( uint8_t * pIndex, uint8_t packetType, uint16_t packetId, - size_t remainingLength, + uint32_t remainingLength, MQTTSuccessFailReasonCode_t reasonCode ) { uint8_t * pIndexLocal = pIndex; @@ -538,7 +543,7 @@ uint8_t * serializeConnectFixedHeader( uint8_t * pIndex, /*-----------------------------------------------------------*/ -uint8_t * serializeSubscribeHeader( size_t remainingLength, +uint8_t * serializeSubscribeHeader( uint32_t remainingLength, uint8_t * pIndex, uint16_t packetId ) { @@ -562,7 +567,7 @@ uint8_t * serializeSubscribeHeader( size_t remainingLength, /*-----------------------------------------------------------*/ -uint8_t * serializeUnsubscribeHeader( size_t remainingLength, +uint8_t * serializeUnsubscribeHeader( uint32_t remainingLength, uint8_t * pIndex, uint16_t packetId ) { @@ -588,7 +593,7 @@ uint8_t * serializeUnsubscribeHeader( size_t remainingLength, uint8_t * serializeDisconnectFixed( uint8_t * pIndex, MQTTSuccessFailReasonCode_t * pReasonCode, - size_t remainingLength ) + uint32_t remainingLength ) { uint8_t * pIndexLocal = pIndex; diff --git a/source/include/core_mqtt.h b/source/include/core_mqtt.h index 70b10772..9bb6a49e 100644 --- a/source/include/core_mqtt.h +++ b/source/include/core_mqtt.h @@ -88,7 +88,7 @@ typedef struct MQTTVec MQTTVec_t; * * @return The time elapsed in milliseconds. */ -typedef uint32_t (* MQTTGetCurrentTimeFunc_t )( void ); +typedef uint32_t ( * MQTTGetCurrentTimeFunc_t )( void ); /** * @ingroup mqtt_callback_types @@ -162,12 +162,12 @@ typedef uint32_t (* MQTTGetCurrentTimeFunc_t )( void ); * making sure that it would be able to process the * received packet again. */ -typedef bool (* MQTTEventCallback_t )( struct MQTTContext * pContext, - struct MQTTPacketInfo * pPacketInfo, - struct MQTTDeserializedInfo * pDeserializedInfo, - enum MQTTSuccessFailReasonCode * pReasonCode, - struct MQTTPropBuilder * pSendPropsBuffer, - struct MQTTPropBuilder * pGetPropsBuffer ); +typedef bool ( * MQTTEventCallback_t )( struct MQTTContext * pContext, + struct MQTTPacketInfo * pPacketInfo, + struct MQTTDeserializedInfo * pDeserializedInfo, + enum MQTTSuccessFailReasonCode * pReasonCode, + struct MQTTPropBuilder * pSendPropsBuffer, + struct MQTTPropBuilder * pGetPropsBuffer ); /** * @brief User defined callback used to store outgoing publishes. Used to track any publish @@ -182,9 +182,9 @@ typedef bool (* MQTTEventCallback_t )( struct MQTTContext * pContext, * @return True if the copy is successful else false. */ /* @[define_mqtt_retransmitstorepacket] */ -typedef bool ( * MQTTStorePacketForRetransmit)( struct MQTTContext * pContext, - uint16_t packetId, - MQTTVec_t * pMqttVec ); +typedef bool ( * MQTTStorePacketForRetransmit )( struct MQTTContext * pContext, + uint16_t packetId, + MQTTVec_t * pMqttVec ); /* @[define_mqtt_retransmitstorepacket] */ /** @@ -202,10 +202,10 @@ typedef bool ( * MQTTStorePacketForRetransmit)( struct MQTTContext * pContext, * @return True if the retreive is successful else false. */ /* @[define_mqtt_retransmitretrievepacket] */ -typedef bool ( * MQTTRetrievePacketForRetransmit)( struct MQTTContext * pContext, - uint16_t packetId, - uint8_t ** pSerializedMqttVec, - size_t * pSerializedMqttVecLen ); +typedef bool ( * MQTTRetrievePacketForRetransmit )( struct MQTTContext * pContext, + uint16_t packetId, + uint8_t ** pSerializedMqttVec, + size_t * pSerializedMqttVecLen ); /* @[define_mqtt_retransmitretrievepacket] */ /** @@ -216,8 +216,8 @@ typedef bool ( * MQTTRetrievePacketForRetransmit)( struct MQTTContext * pContext * @param[in] packetId Copied publish packet identifier. */ /* @[define_mqtt_retransmitclearpacket] */ -typedef void (* MQTTClearPacketForRetransmit)( struct MQTTContext * pContext, - uint16_t packetId ); +typedef void ( * MQTTClearPacketForRetransmit )( struct MQTTContext * pContext, + uint16_t packetId ); /* @[define_mqtt_retransmitclearpacket] */ /** @@ -1345,9 +1345,9 @@ uint16_t MQTT_GetPacketId( MQTTContext_t * pContext ); * @endcode */ MQTTStatus_t MQTT_MatchTopic( const char * pTopicName, - const uint16_t topicNameLength, + const size_t topicNameLength, const char * pTopicFilter, - const uint16_t topicFilterLength, + const size_t topicFilterLength, bool * pIsMatch ); /** @@ -1463,11 +1463,14 @@ const char * MQTT_Status_strerror( MQTTStatus_t status ); /* @[declare_mqtt_status_strerror] */ /** - * @brief Get the bytes in a #MQTTVec pointer which can store the whole array as a an MQTT packet when calling MQTT_SerializeMQTTVec( void * pAllocatedMem, MQTTVec_t *pVec ) function. + * @brief Get the bytes in a #MQTTVec pointer which can store the whole array as a an + * MQTT packet when calling MQTT_SerializeMQTTVec( void * pAllocatedMem, MQTTVec_t *pVec ) function. * - * @param[in] pVec The #MQTTVec pointer given as input to the user defined #MQTTStorePacketForRetransmit callback function. Must not be NULL. + * @param[in] pVec The #MQTTVec pointer given as input to the user defined + * #MQTTStorePacketForRetransmit callback function. Must not be NULL. * - * @return The bytes in the provided #MQTTVec array which can then be used to set aside memory to be used with MQTT_SerializeMQTTVec( void * pAllocatedMem, MQTTVec_t *pVec ) function. + * @return The bytes in the provided #MQTTVec array which can then be used to + * set aside memory to be used with MQTT_SerializeMQTTVec( void * pAllocatedMem, MQTTVec_t *pVec ) function. */ /* @[declare_mqtt_getbytesinmqttvec] */ size_t MQTT_GetBytesInMQTTVec( const MQTTVec_t * pVec ); @@ -1476,8 +1479,11 @@ size_t MQTT_GetBytesInMQTTVec( const MQTTVec_t * pVec ); /** * @brief Serialize the bytes in an array of #MQTTVec in the provided \p pAllocatedMem * - * @param[in] pAllocatedMem Memory in which to serialize the data in the #MQTTVec array. It must be of size provided by MQTT_GetBytesInMQTTVec( MQTTVec_t *pVec ). Should not be NULL. - * @param[in] pVec The #MQTTVec pointer given as input to the user defined #MQTTStorePacketForRetransmit callback function. Must not be NULL. + * @param[in] pAllocatedMem Memory in which to serialize the data in the #MQTTVec array. + * It must be of size provided by MQTT_GetBytesInMQTTVec( MQTTVec_t *pVec ). + * Should not be NULL. + * @param[in] pVec The #MQTTVec pointer given as input to the user defined + * #MQTTStorePacketForRetransmit callback function. Must not be NULL. */ /* @[declare_mqtt_serializemqttvec] */ void MQTT_SerializeMQTTVec( uint8_t * pAllocatedMem, diff --git a/source/include/core_mqtt_serializer.h b/source/include/core_mqtt_serializer.h index b14bdf09..a7faa451 100644 --- a/source/include/core_mqtt_serializer.h +++ b/source/include/core_mqtt_serializer.h @@ -310,7 +310,7 @@ typedef struct MQTTConnectInfo /** * @brief Length of the client identifier. */ - uint16_t clientIdentifierLength; + size_t clientIdentifierLength; /** * @brief MQTT user name. Set to NULL if not used. @@ -320,7 +320,7 @@ typedef struct MQTTConnectInfo /** * @brief Length of MQTT user name. Set to 0 if not used. */ - uint16_t userNameLength; + size_t userNameLength; /** * @brief MQTT password. Set to NULL if not used. @@ -330,7 +330,7 @@ typedef struct MQTTConnectInfo /** * @brief Length of MQTT password. Set to 0 if not used. */ - uint16_t passwordLength; + size_t passwordLength; } MQTTConnectInfo_t; /** @@ -362,7 +362,7 @@ typedef struct MQTTSubscribeInfo /** * @brief Length of subscription topic filter - unsigned long */ - uint16_t topicFilterLength; + size_t topicFilterLength; /** * @brief no local option for subscription. Include protocol error if noLocalOption = 1 in a shared subscription */ @@ -416,7 +416,7 @@ typedef struct MQTTPublishInfo /** * @brief Length of topic name. */ - uint16_t topicNameLength; + size_t topicNameLength; /** * @brief Message payload. @@ -431,7 +431,7 @@ typedef struct MQTTPublishInfo /** * @brief Length of the properties. */ - uint32_t propertyLength; + size_t propertyLength; } MQTTPublishInfo_t; @@ -469,8 +469,8 @@ typedef struct MQTTPacketInfo typedef struct MQTTPropBuilder { uint8_t * pBuffer; /**< @brief Pointer to the buffer for storing properties. */ - uint32_t bufferLength; /**< @brief Total length of the buffer available for properties. */ - uint32_t currentIndex; /**< @brief Current position in the buffer where next property will be written. */ + size_t bufferLength; /**< @brief Total length of the buffer available for properties. */ + size_t currentIndex; /**< @brief Current position in the buffer where next property will be written. */ uint32_t fieldSet; /**< @brief Bitfield tracking which properties have been added. */ } MQTTPropBuilder_t; @@ -703,19 +703,19 @@ typedef struct MQTTUserProperty /** * @brief key. */ - const char* pKey; + const char * pKey; /** * @brief Length of the key. */ - uint16_t keyLength; + size_t keyLength; /** * @brief value. */ - const char* pValue; + const char * pValue; /** * @brief Length of the value. */ - uint16_t valueLength; + size_t valueLength; } MQTTUserProperty_t; /** @@ -938,8 +938,8 @@ MQTTStatus_t MQTT_SerializeConnect( const MQTTConnectInfo_t * pConnectInfo, MQTTStatus_t MQTT_GetSubscribePacketSize( const MQTTSubscribeInfo_t * pSubscriptionList, size_t subscriptionCount, const MQTTPropBuilder_t * pSubscribeProperties, - size_t * pRemainingLength, - size_t * pPacketSize, + uint32_t * pRemainingLength, + uint32_t * pPacketSize, uint32_t maxPacketSize ); /* @[declare_mqtt_getsubscribepacketsize] */ @@ -1013,7 +1013,7 @@ MQTTStatus_t MQTT_SerializeSubscribe( const MQTTSubscribeInfo_t * pSubscriptionL size_t subscriptionCount, const MQTTPropBuilder_t * pSubscribeProperties, uint16_t packetId, - size_t remainingLength, + uint32_t remainingLength, const MQTTFixedBuffer_t * pFixedBuffer ); /* @[declare_mqtt_serializesubscribe] */ @@ -1074,12 +1074,12 @@ MQTTStatus_t MQTT_SerializeSubscribe( const MQTTSubscribeInfo_t * pSubscriptionL * @endcode */ /* @[declare_mqtt_getunsubscribepacketsize] */ -MQTTStatus_t MQTT_GetUnsubscribePacketSize( const MQTTSubscribeInfo_t* pSubscriptionList, +MQTTStatus_t MQTT_GetUnsubscribePacketSize( const MQTTSubscribeInfo_t * pSubscriptionList, size_t subscriptionCount, const MQTTPropBuilder_t * pUnsubscribeProperties, - size_t* pRemainingLength, - size_t* pPacketSize, - uint32_t maxPacketSize); + uint32_t * pRemainingLength, + uint32_t * pPacketSize, + uint32_t maxPacketSize ); /* @[declare_mqtt_getunsubscribepacketsize] */ /** @@ -1161,7 +1161,7 @@ MQTTStatus_t MQTT_SerializeUnsubscribe( const MQTTSubscribeInfo_t * pSubscriptio size_t subscriptionCount, const MQTTPropBuilder_t * pUnsubscribeProperties, uint16_t packetId, - size_t remainingLength, + uint32_t remainingLength, const MQTTFixedBuffer_t * pFixedBuffer ); /* @[declare_mqtt_serializeunsubscribe] */ @@ -1227,9 +1227,9 @@ MQTTStatus_t MQTT_SerializeUnsubscribe( const MQTTSubscribeInfo_t * pSubscriptio /* @[declare_mqtt_getpublishpacketsize] */ MQTTStatus_t MQTT_GetPublishPacketSize( const MQTTPublishInfo_t * pPublishInfo, const MQTTPropBuilder_t * pPublishProperties, - size_t * pRemainingLength, - size_t * pPacketSize, - uint32_t maxPacketSize); + uint32_t * pRemainingLength, + uint32_t * pPacketSize, + uint32_t maxPacketSize ); /* @[declare_mqtt_getpublishpacketsize] */ /** @@ -1302,7 +1302,7 @@ MQTTStatus_t MQTT_GetPublishPacketSize( const MQTTPublishInfo_t * pPublishInfo, MQTTStatus_t MQTT_SerializePublish( const MQTTPublishInfo_t * pPublishInfo, const MQTTPropBuilder_t * pPublishProperties, uint16_t packetId, - size_t remainingLength, + uint32_t remainingLength, const MQTTFixedBuffer_t * pFixedBuffer ); /* @[declare_mqtt_serializepublish] */ @@ -1321,7 +1321,7 @@ MQTTStatus_t MQTT_SerializePublish( const MQTTPublishInfo_t * pPublishInfo, */ /* @[declare_mqtt_serializepublishheaderwithouttopic] */ MQTTStatus_t MQTT_SerializePublishHeaderWithoutTopic( const MQTTPublishInfo_t * pPublishInfo, - size_t remainingLength, + uint32_t remainingLength, uint8_t * pBuffer, size_t * headerSize ); /* @[declare_mqtt_serializepublishheaderwithouttopic] */ @@ -1407,7 +1407,7 @@ MQTTStatus_t MQTT_SerializePublishHeaderWithoutTopic( const MQTTPublishInfo_t * MQTTStatus_t MQTT_SerializePublishHeader( const MQTTPublishInfo_t * pPublishInfo, const MQTTPropBuilder_t * pPublishProperties, uint16_t packetId, - size_t remainingLength, + uint32_t remainingLength, const MQTTFixedBuffer_t * pFixedBuffer, size_t * pHeaderSize ); /* @[declare_mqtt_serializepublishheader] */ @@ -1505,8 +1505,8 @@ MQTTStatus_t MQTT_SerializeAck( const MQTTFixedBuffer_t * pFixedBuffer, */ /* @[declare_mqtt_getdisconnectpacketsize] */ MQTTStatus_t MQTT_GetDisconnectPacketSize( const MQTTPropBuilder_t * pDisconnectProperties, - size_t * pRemainingLength, - size_t * pPacketSize, + uint32_t * pRemainingLength, + uint32_t * pPacketSize, uint32_t maxPacketSize, MQTTSuccessFailReasonCode_t * pReasonCode ); /* @[declare_mqtt_getdisconnectpacketsize] */ @@ -1566,7 +1566,7 @@ MQTTStatus_t MQTT_GetDisconnectPacketSize( const MQTTPropBuilder_t * pDisconnect /* @[declare_mqtt_serializedisconnect] */ MQTTStatus_t MQTT_SerializeDisconnect( const MQTTPropBuilder_t * pDisconnectProperties, MQTTSuccessFailReasonCode_t * pReasonCode, - size_t remainingLength, + uint32_t remainingLength, const MQTTFixedBuffer_t * pFixedBuffer ); /* @[declare_mqtt_serializedisconnect] */ @@ -1595,7 +1595,7 @@ MQTTStatus_t MQTT_SerializeDisconnect( const MQTTPropBuilder_t * pDisconnectProp * @endcode */ /* @[declare_mqtt_getpingreqpacketsize] */ -MQTTStatus_t MQTT_GetPingreqPacketSize( size_t * pPacketSize ); +MQTTStatus_t MQTT_GetPingreqPacketSize( uint32_t * pPacketSize ); /* @[declare_mqtt_getpingreqpacketsize] */ /** @@ -1707,8 +1707,8 @@ MQTTStatus_t MQTT_SerializePingreq( const MQTTFixedBuffer_t * pFixedBuffer ); * @endcode */ /* @[declare_mqtt_deserializepublish] */ -MQTTStatus_t MQTT_DeserializePublish( const MQTTPacketInfo_t* pIncomingPacket, - uint16_t* pPacketId, +MQTTStatus_t MQTT_DeserializePublish( const MQTTPacketInfo_t * pIncomingPacket, + uint16_t * pPacketId, MQTTPublishInfo_t * pPublishInfo, MQTTPropBuilder_t * propBuffer, uint32_t maxPacketSize, @@ -1748,11 +1748,11 @@ MQTTStatus_t MQTT_DeserializePublish( const MQTTPacketInfo_t* pIncomingPacket, * receiveIncomingPacket(&incomingPacket); * * // Deserialize ack information if the incoming packet is a publish ack. - * status = MQTT_DeserializeAck(&incomingPacket, - * &packetId, - * &reasonCode, - * &propBuffer, - * &connectionProperties); + * status = MQTT_DeserializeAck( &incomingPacket, + * &packetId, + * &reasonCode, + * &propBuffer, + * &connectionProperties ); * if(status == MQTTSuccess) * { * // Ack information is now available. @@ -1886,7 +1886,7 @@ MQTTStatus_t MQTT_ProcessIncomingPacketTypeAndLength( const uint8_t * pBuffer, * #MQTTBadParameter for invalid parameters */ /* @[declare_mqtt_updateduplicatepublishflag] */ -MQTTStatus_t MQTT_UpdateDuplicatePublishFlag( uint8_t * pHeader , bool set ); +MQTTStatus_t MQTT_UpdateDuplicatePublishFlag( uint8_t * pHeader, bool set ); /* @[declare_mqtt_updateduplicatepublishflag] */ /** @@ -1933,7 +1933,7 @@ MQTTStatus_t MQTTPropertyBuilder_Init( MQTTPropBuilder_t * pPropertyBuilder, * - #MQTTSuccess , #MQTTBadParameter or #MQTTBadResponse. */ /* @[declare_mqtt_validatewillproperties] */ -MQTTStatus_t MQTT_ValidateWillProperties( const MQTTPropBuilder_t * pPropertyBuilder); +MQTTStatus_t MQTT_ValidateWillProperties( const MQTTPropBuilder_t * pPropertyBuilder ); /* @[declare_mqtt_validatewillproperties] */ @@ -1993,7 +1993,7 @@ MQTTStatus_t MQTT_ValidateConnectProperties( const MQTTPropBuilder_t * pProperty */ /* @[declare_mqttpropadd_subscriptionid] */ -MQTTStatus_t MQTTPropAdd_SubscriptionId( MQTTPropBuilder_t* pPropertyBuilder, +MQTTStatus_t MQTTPropAdd_SubscriptionId( MQTTPropBuilder_t * pPropertyBuilder, uint32_t subscriptionId, const uint8_t * pOptionalMqttPacketType ); /* @[declare_mqttpropadd_subscriptionid] */ @@ -2015,8 +2015,8 @@ MQTTStatus_t MQTTPropAdd_SubscriptionId( MQTTPropBuilder_t* pPropertyBuilder, * - #MQTTNoMemory if the property builder has insufficient space */ /* @[declare_mqttpropadd_userprop] */ -MQTTStatus_t MQTTPropAdd_UserProp( MQTTPropBuilder_t* pPropertyBuilder, - const MQTTUserProperty_t* userProperty, +MQTTStatus_t MQTTPropAdd_UserProp( MQTTPropBuilder_t * pPropertyBuilder, + const MQTTUserProperty_t * userProperty, const uint8_t * pOptionalMqttPacketType ); /* @[declare_mqttpropadd_userprop] */ @@ -2036,7 +2036,7 @@ MQTTStatus_t MQTTPropAdd_UserProp( MQTTPropBuilder_t* pPropertyBuilder, * - #MQTTNoMemory if the property builder has insufficient space */ /* @[declare_mqttpropadd_sessionexpiry] */ -MQTTStatus_t MQTTPropAdd_SessionExpiry( MQTTPropBuilder_t* pPropertyBuilder, +MQTTStatus_t MQTTPropAdd_SessionExpiry( MQTTPropBuilder_t * pPropertyBuilder, uint32_t sessionExpiry, const uint8_t * pOptionalMqttPacketType ); /* @[declare_mqttpropadd_sessionexpiry] */ @@ -2059,7 +2059,7 @@ MQTTStatus_t MQTTPropAdd_SessionExpiry( MQTTPropBuilder_t* pPropertyBuilder, * - #MQTTNoMemory if the property builder has insufficient space */ /* @[declare_mqttpropadd_receivemax] */ -MQTTStatus_t MQTTPropAdd_ReceiveMax( MQTTPropBuilder_t* pPropertyBuilder, +MQTTStatus_t MQTTPropAdd_ReceiveMax( MQTTPropBuilder_t * pPropertyBuilder, uint16_t receiveMax, const uint8_t * pOptionalMqttPacketType ); /* @[declare_mqttpropadd_receivemax] */ @@ -2081,7 +2081,7 @@ MQTTStatus_t MQTTPropAdd_ReceiveMax( MQTTPropBuilder_t* pPropertyBuilder, * - #MQTTNoMemory if the property builder has insufficient space */ /* @[declare_mqttpropadd_maxpacketsize] */ -MQTTStatus_t MQTTPropAdd_MaxPacketSize( MQTTPropBuilder_t* pPropertyBuilder, +MQTTStatus_t MQTTPropAdd_MaxPacketSize( MQTTPropBuilder_t * pPropertyBuilder, uint32_t maxPacketSize, const uint8_t * pOptionalMqttPacketType ); /* @[declare_mqttpropadd_maxpacketsize] */ @@ -2103,7 +2103,7 @@ MQTTStatus_t MQTTPropAdd_MaxPacketSize( MQTTPropBuilder_t* pPropertyBuilder, * - #MQTTNoMemory if the property builder has insufficient space */ /* @[declare_mqttpropadd_topicaliasmax] */ -MQTTStatus_t MQTTPropAdd_TopicAliasMax( MQTTPropBuilder_t* pPropertyBuilder, +MQTTStatus_t MQTTPropAdd_TopicAliasMax( MQTTPropBuilder_t * pPropertyBuilder, uint16_t topicAliasMax, const uint8_t * pOptionalMqttPacketType ); /* @[declare_mqttpropadd_topicaliasmax] */ @@ -2125,7 +2125,7 @@ MQTTStatus_t MQTTPropAdd_TopicAliasMax( MQTTPropBuilder_t* pPropertyBuilder, * - #MQTTNoMemory if the property builder has insufficient space */ /* @[declare_mqttpropadd_requestrespinfo] */ -MQTTStatus_t MQTTPropAdd_RequestRespInfo( MQTTPropBuilder_t* pPropertyBuilder, +MQTTStatus_t MQTTPropAdd_RequestRespInfo( MQTTPropBuilder_t * pPropertyBuilder, bool requestResponseInfo, const uint8_t * pOptionalMqttPacketType ); /* @[declare_mqttpropadd_requestrespinfo] */ @@ -2147,7 +2147,7 @@ MQTTStatus_t MQTTPropAdd_RequestRespInfo( MQTTPropBuilder_t* pPropertyBuilder, * - #MQTTNoMemory if the property builder has insufficient space */ /* @[declare_mqttpropadd_requestprobinfo] */ -MQTTStatus_t MQTTPropAdd_RequestProbInfo( MQTTPropBuilder_t* pPropertyBuilder, +MQTTStatus_t MQTTPropAdd_RequestProbInfo( MQTTPropBuilder_t * pPropertyBuilder, bool requestProblemInfo, const uint8_t * pOptionalMqttPacketType ); /* @[declare_mqttpropadd_requestprobinfo] */ @@ -2159,7 +2159,7 @@ MQTTStatus_t MQTTPropAdd_RequestProbInfo( MQTTPropBuilder_t* pPropertyBuilder, * * @param[out] pPropertyBuilder Pointer to the property builder structure. * @param[in] authMethod Pointer to the authentication method string. - * @param[in] authMethodLength Length of the authentication method string. + * @param[in] authMethodLength Length of the authentication method string (must be less than 65536). * @param[in] pOptionalMqttPacketType Optional MQTT packet type for which the property * is being added. The function will check whether the given property can be * added to the packet type if it is provided. @@ -2170,9 +2170,9 @@ MQTTStatus_t MQTTPropAdd_RequestProbInfo( MQTTPropBuilder_t* pPropertyBuilder, * - #MQTTNoMemory if the property builder has insufficient space */ /* @[declare_mqttpropadd_authmethod] */ -MQTTStatus_t MQTTPropAdd_AuthMethod( MQTTPropBuilder_t* pPropertyBuilder, - const char* authMethod, - uint16_t authMethodLength, +MQTTStatus_t MQTTPropAdd_AuthMethod( MQTTPropBuilder_t * pPropertyBuilder, + const char * authMethod, + size_t authMethodLength, const uint8_t * pOptionalMqttPacketType ); /* @[declare_mqttpropadd_authmethod] */ @@ -2183,7 +2183,7 @@ MQTTStatus_t MQTTPropAdd_AuthMethod( MQTTPropBuilder_t* pPropertyBuilder, * * @param[out] pPropertyBuilder Pointer to the property builder structure. * @param[in] authData Pointer to the authentication data. - * @param[in] authDataLength Length of the authentication data. + * @param[in] authDataLength Length of the authentication data (must be less than 65536). * @param[in] pOptionalMqttPacketType Optional MQTT packet type for which the property * is being added. The function will check whether the given property can be * added to the packet type if it is provided. @@ -2194,9 +2194,9 @@ MQTTStatus_t MQTTPropAdd_AuthMethod( MQTTPropBuilder_t* pPropertyBuilder, * - #MQTTNoMemory if the property builder has insufficient space */ /* @[declare_mqttpropadd_authdata] */ -MQTTStatus_t MQTTPropAdd_AuthData( MQTTPropBuilder_t* pPropertyBuilder, - const char* authData, - uint16_t authDataLength, +MQTTStatus_t MQTTPropAdd_AuthData( MQTTPropBuilder_t * pPropertyBuilder, + const char * authData, + size_t authDataLength, const uint8_t * pOptionalMqttPacketType ); /* @[declare_mqttpropadd_authdata] */ @@ -2217,7 +2217,7 @@ MQTTStatus_t MQTTPropAdd_AuthData( MQTTPropBuilder_t* pPropertyBuilder, * - #MQTTNoMemory if the property builder has insufficient space */ /* @[declare_mqttpropadd_payloadformat] */ -MQTTStatus_t MQTTPropAdd_PayloadFormat( MQTTPropBuilder_t* pPropertyBuilder, +MQTTStatus_t MQTTPropAdd_PayloadFormat( MQTTPropBuilder_t * pPropertyBuilder, bool payloadFormat, const uint8_t * pOptionalMqttPacketType ); /* @[declare_mqttpropadd_payloadformat] */ @@ -2239,7 +2239,7 @@ MQTTStatus_t MQTTPropAdd_PayloadFormat( MQTTPropBuilder_t* pPropertyBuilder, * - #MQTTNoMemory if the property builder has insufficient space */ /* @[declare_mqttpropadd_messageexpiry] */ -MQTTStatus_t MQTTPropAdd_MessageExpiry( MQTTPropBuilder_t* pPropertyBuilder, +MQTTStatus_t MQTTPropAdd_MessageExpiry( MQTTPropBuilder_t * pPropertyBuilder, uint32_t messageExpiry, const uint8_t * pOptionalMqttPacketType ); /* @[declare_mqttpropadd_messageexpiry] */ @@ -2283,7 +2283,7 @@ MQTTStatus_t MQTTPropAdd_WillDelayInterval( MQTTPropBuilder_t * pPropertyBuilder * - #MQTTNoMemory if the property builder has insufficient space */ /* @[declare_mqttpropadd_topicalias] */ -MQTTStatus_t MQTTPropAdd_TopicAlias( MQTTPropBuilder_t* pPropertyBuilder, +MQTTStatus_t MQTTPropAdd_TopicAlias( MQTTPropBuilder_t * pPropertyBuilder, uint16_t topicAlias, const uint8_t * pOptionalMqttPacketType ); /* @[declare_mqttpropadd_topicalias] */ @@ -2295,7 +2295,7 @@ MQTTStatus_t MQTTPropAdd_TopicAlias( MQTTPropBuilder_t* pPropertyBuilder, * * @param[out] pPropertyBuilder Pointer to the property builder structure. * @param[in] responseTopic Pointer to the response topic string. - * @param[in] responseTopicLength Length of the response topic string. + * @param[in] responseTopicLength Length of the response topic string (must be less than 65536). * @param[in] pOptionalMqttPacketType Optional MQTT packet type for which the property * is being added. The function will check whether the given property can be * added to the packet type if it is provided. @@ -2306,10 +2306,10 @@ MQTTStatus_t MQTTPropAdd_TopicAlias( MQTTPropBuilder_t* pPropertyBuilder, * - #MQTTNoMemory if the property builder has insufficient space */ /* @[declare_mqttpropadd_responsetopic] */ -MQTTStatus_t MQTTPropAdd_ResponseTopic( MQTTPropBuilder_t* pPropertyBuilder, - const char* responseTopic, - uint16_t responseTopicLength, - const uint8_t * pOptionalMqttPacketType); +MQTTStatus_t MQTTPropAdd_ResponseTopic( MQTTPropBuilder_t * pPropertyBuilder, + const char * responseTopic, + size_t responseTopicLength, + const uint8_t * pOptionalMqttPacketType ); /* @[declare_mqttpropadd_responsetopic] */ /** * @brief Adds Correlation Data property to the MQTT property builder. @@ -2318,7 +2318,7 @@ MQTTStatus_t MQTTPropAdd_ResponseTopic( MQTTPropBuilder_t* pPropertyBuilder, * * @param[out] pPropertyBuilder Pointer to the property builder structure. * @param[in] pCorrelationData Pointer to the correlation data. - * @param[in] correlationLength Length of the correlation data. + * @param[in] correlationLength Length of the correlation data (must be less than 65536). * @param[in] pOptionalMqttPacketType Optional MQTT packet type for which the property * is being added. The function will check whether the given property can be * added to the packet type if it is provided. @@ -2329,9 +2329,9 @@ MQTTStatus_t MQTTPropAdd_ResponseTopic( MQTTPropBuilder_t* pPropertyBuilder, * - #MQTTNoMemory if the property builder has insufficient space */ /* @[declare_mqttpropadd_correlationdata] */ -MQTTStatus_t MQTTPropAdd_CorrelationData( MQTTPropBuilder_t* pPropertyBuilder, - const void* pCorrelationData, - uint16_t correlationLength, +MQTTStatus_t MQTTPropAdd_CorrelationData( MQTTPropBuilder_t * pPropertyBuilder, + const void * pCorrelationData, + size_t correlationLength, const uint8_t * pOptionalMqttPacketType ); /* @[declare_mqttpropadd_correlationdata] */ @@ -2342,7 +2342,7 @@ MQTTStatus_t MQTTPropAdd_CorrelationData( MQTTPropBuilder_t* pPropertyBuilder, * * @param[out] pPropertyBuilder Pointer to the property builder structure. * @param[in] contentType Pointer to the content type string. - * @param[in] contentTypeLength Length of the content type string. + * @param[in] contentTypeLength Length of the content type string (must be less than 65536). * @param[in] pOptionalMqttPacketType Optional MQTT packet type for which the property * is being added. The function will check whether the given property can be * added to the packet type if it is provided. @@ -2353,9 +2353,9 @@ MQTTStatus_t MQTTPropAdd_CorrelationData( MQTTPropBuilder_t* pPropertyBuilder, * - #MQTTNoMemory if the property builder has insufficient space */ /* @[declare_mqttpropadd_contenttype] */ -MQTTStatus_t MQTTPropAdd_ContentType( MQTTPropBuilder_t* pPropertyBuilder, - const char* contentType, - uint16_t contentTypeLength, +MQTTStatus_t MQTTPropAdd_ContentType( MQTTPropBuilder_t * pPropertyBuilder, + const char * contentType, + size_t contentTypeLength, const uint8_t * pOptionalMqttPacketType ); /* @[declare_mqttpropadd_contenttype] */ @@ -2366,7 +2366,7 @@ MQTTStatus_t MQTTPropAdd_ContentType( MQTTPropBuilder_t* pPropertyBuilder, * * @param[out] pPropertyBuilder Pointer to the property builder structure. * @param[in] pReasonString Pointer to the reason string. - * @param[in] reasonStringLength Length of the reason string. + * @param[in] reasonStringLength Length of the reason string (must be less than 65536). * @param[in] pOptionalMqttPacketType Optional MQTT packet type for which the property * is being added. The function will check whether the given property can be * added to the packet type if it is provided. @@ -2377,9 +2377,9 @@ MQTTStatus_t MQTTPropAdd_ContentType( MQTTPropBuilder_t* pPropertyBuilder, * - #MQTTNoMemory if the property builder has insufficient space */ /* @[declare_mqttpropadd_reasonstring] */ -MQTTStatus_t MQTTPropAdd_ReasonString( MQTTPropBuilder_t* pPropertyBuilder, - const char* pReasonString, - uint16_t reasonStringLength, +MQTTStatus_t MQTTPropAdd_ReasonString( MQTTPropBuilder_t * pPropertyBuilder, + const char * pReasonString, + size_t reasonStringLength, const uint8_t * pOptionalMqttPacketType ); /* @[declare_mqttpropadd_reasonstring] */ @@ -2396,7 +2396,8 @@ MQTTStatus_t MQTTPropAdd_ReasonString( MQTTPropBuilder_t* pPropertyBuilder, * - #MQTTBadParameter if an invalid parameter is passed */ /* @[declare_mqtt_validatesubscribeproperties] */ -MQTTStatus_t MQTT_ValidateSubscribeProperties( bool isSubscriptionIdAvailable, const MQTTPropBuilder_t* propBuilder ); +MQTTStatus_t MQTT_ValidateSubscribeProperties( bool isSubscriptionIdAvailable, + const MQTTPropBuilder_t * propBuilder ); /* @[declare_mqtt_validatesubscribeproperties] */ /** @@ -2426,7 +2427,7 @@ MQTTStatus_t MQTT_ValidateSubscribeProperties( bool isSubscriptionIdAvailable, c * // ... * * // Update connect properties - * status = updateContextWithConnectProps(&propBuilder, &connectionProperties); + * status = updateContextWithConnectProps( &propBuilder, &connectionProperties ); * * if(status == MQTTSuccess) * { @@ -2435,7 +2436,8 @@ MQTTStatus_t MQTT_ValidateSubscribeProperties( bool isSubscriptionIdAvailable, c * @endcode */ -MQTTStatus_t updateContextWithConnectProps( const MQTTPropBuilder_t* pPropBuilder, MQTTConnectionProperties_t* pConnectProperties ); +MQTTStatus_t updateContextWithConnectProps( const MQTTPropBuilder_t * pPropBuilder, + MQTTConnectionProperties_t * pConnectProperties ); /** * @brief Get the property type at the current index in the property builder. @@ -2454,7 +2456,7 @@ MQTTStatus_t updateContextWithConnectProps( const MQTTPropBuilder_t* pPropBuilde * or the property type is not recognized. */ MQTTStatus_t MQTT_GetNextPropertyType( MQTTPropBuilder_t * mqttPropBuilder, - uint32_t * index, + size_t * index, uint8_t * property ); /** @@ -2519,7 +2521,7 @@ MQTTStatus_t MQTT_GetNextPropertyType( MQTTPropBuilder_t * mqttPropBuilder, * @endcode */ MQTTStatus_t MQTT_SkipNextProperty( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex ); + size_t * currentIndex ); /** * @brief Get User Property from property builder. @@ -2533,7 +2535,7 @@ MQTTStatus_t MQTT_SkipNextProperty( MQTTPropBuilder_t * pPropertyBuilder, */ /* @[declare_mqttpropget_userprop] */ MQTTStatus_t MQTTPropGet_UserProp( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex, + size_t * currentIndex, MQTTUserProperty_t * pUserProperty ); /* @[declare_mqttpropget_userprop] */ @@ -2549,7 +2551,7 @@ MQTTStatus_t MQTTPropGet_UserProp( MQTTPropBuilder_t * pPropertyBuilder, */ /* @[declare_mqttpropget_sessionexpiry] */ MQTTStatus_t MQTTPropGet_SessionExpiry( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex, + size_t * currentIndex, uint32_t * pSessionExpiry ); /* @[declare_mqttpropget_sessionexpiry] */ @@ -2565,7 +2567,7 @@ MQTTStatus_t MQTTPropGet_SessionExpiry( MQTTPropBuilder_t * pPropertyBuilder, */ /* @[declare_mqttpropget_receivemax] */ MQTTStatus_t MQTTPropGet_ReceiveMax( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex, + size_t * currentIndex, uint16_t * pReceiveMax ); /* @[declare_mqttpropget_receivemax] */ @@ -2581,7 +2583,7 @@ MQTTStatus_t MQTTPropGet_ReceiveMax( MQTTPropBuilder_t * pPropertyBuilder, */ /* @[declare_mqttpropget_maxqos] */ MQTTStatus_t MQTTPropGet_MaxQos( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex, + size_t * currentIndex, uint8_t * pMaxQos ); /* @[declare_mqttpropget_maxqos] */ @@ -2597,7 +2599,7 @@ MQTTStatus_t MQTTPropGet_MaxQos( MQTTPropBuilder_t * pPropertyBuilder, */ /* @[declare_mqttpropget_retainavailable] */ MQTTStatus_t MQTTPropGet_RetainAvailable( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex, + size_t * currentIndex, uint8_t * pRetainAvailable ); /* @[declare_mqttpropget_retainavailable] */ @@ -2613,7 +2615,7 @@ MQTTStatus_t MQTTPropGet_RetainAvailable( MQTTPropBuilder_t * pPropertyBuilder, */ /* @[declare_mqttpropget_maxpacketsize] */ MQTTStatus_t MQTTPropGet_MaxPacketSize( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex, + size_t * currentIndex, uint32_t * pMaxPacketSize ); /* @[declare_mqttpropget_maxpacketsize] */ @@ -2630,9 +2632,9 @@ MQTTStatus_t MQTTPropGet_MaxPacketSize( MQTTPropBuilder_t * pPropertyBuilder, */ /* @[declare_mqttpropget_assignedclientid] */ MQTTStatus_t MQTTPropGet_AssignedClientId( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex, + size_t * currentIndex, const char ** pClientId, - uint16_t * pClientIdLength ); + size_t * pClientIdLength ); /* @[declare_mqttpropget_assignedclientid] */ /** @@ -2647,7 +2649,7 @@ MQTTStatus_t MQTTPropGet_AssignedClientId( MQTTPropBuilder_t * pPropertyBuilder, */ /* @[declare_mqttpropget_topicaliasmax] */ MQTTStatus_t MQTTPropGet_TopicAliasMax( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex, + size_t * currentIndex, uint16_t * pTopicAliasMax ); /* @[declare_mqttpropget_topicaliasmax] */ @@ -2664,9 +2666,9 @@ MQTTStatus_t MQTTPropGet_TopicAliasMax( MQTTPropBuilder_t * pPropertyBuilder, */ /* @[declare_mqttpropget_reasonstring] */ MQTTStatus_t MQTTPropGet_ReasonString( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex, + size_t * currentIndex, const char ** pReasonString, - uint16_t * pReasonStringLength ); + size_t * pReasonStringLength ); /* @[declare_mqttpropget_reasonstring] */ /** @@ -2681,7 +2683,7 @@ MQTTStatus_t MQTTPropGet_ReasonString( MQTTPropBuilder_t * pPropertyBuilder, */ /* @[declare_mqttpropget_wildcardid] */ MQTTStatus_t MQTTPropGet_WildcardId( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex, + size_t * currentIndex, uint8_t * pWildcardAvailable ); /* @[declare_mqttpropget_wildcardid] */ @@ -2697,7 +2699,7 @@ MQTTStatus_t MQTTPropGet_WildcardId( MQTTPropBuilder_t * pPropertyBuilder, */ /* @[declare_mqttpropget_subsidavailable] */ MQTTStatus_t MQTTPropGet_SubsIdAvailable( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex, + size_t * currentIndex, uint8_t * pSubsIdAvailable ); /* @[declare_mqttpropget_subsidavailable] */ @@ -2713,7 +2715,7 @@ MQTTStatus_t MQTTPropGet_SubsIdAvailable( MQTTPropBuilder_t * pPropertyBuilder, */ /* @[declare_mqttpropget_sharedsubavailable] */ MQTTStatus_t MQTTPropGet_SharedSubAvailable( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex, + size_t * currentIndex, uint8_t * pSharedSubAvailable ); /* @[declare_mqttpropget_sharedsubavailable] */ @@ -2729,7 +2731,7 @@ MQTTStatus_t MQTTPropGet_SharedSubAvailable( MQTTPropBuilder_t * pPropertyBuilde */ /* @[declare_mqttpropget_serverkeepalive] */ MQTTStatus_t MQTTPropGet_ServerKeepAlive( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex, + size_t * currentIndex, uint16_t * pServerKeepAlive ); /* @[declare_mqttpropget_serverkeepalive] */ @@ -2746,9 +2748,9 @@ MQTTStatus_t MQTTPropGet_ServerKeepAlive( MQTTPropBuilder_t * pPropertyBuilder, */ /* @[declare_mqttpropget_responseinfo] */ MQTTStatus_t MQTTPropGet_ResponseInfo( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex, + size_t * currentIndex, const char ** pResponseInfo, - uint16_t * pResponseInfoLength ); + size_t * pResponseInfoLength ); /* @[declare_mqttpropget_responseinfo] */ /** @@ -2764,9 +2766,9 @@ MQTTStatus_t MQTTPropGet_ResponseInfo( MQTTPropBuilder_t * pPropertyBuilder, */ /* @[declare_mqttpropget_serverref] */ MQTTStatus_t MQTTPropGet_ServerRef( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex, + size_t * currentIndex, const char ** pServerRef, - uint16_t * pServerRefLength ); + size_t * pServerRefLength ); /* @[declare_mqttpropget_serverref] */ /** @@ -2782,9 +2784,9 @@ MQTTStatus_t MQTTPropGet_ServerRef( MQTTPropBuilder_t * pPropertyBuilder, */ /* @[declare_mqttpropget_authmethod] */ MQTTStatus_t MQTTPropGet_AuthMethod( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex, + size_t * currentIndex, const char ** pAuthMethod, - uint16_t * pAuthMethodLen ); + size_t * pAuthMethodLen ); /* @[declare_mqttpropget_authmethod] */ /** @@ -2800,9 +2802,9 @@ MQTTStatus_t MQTTPropGet_AuthMethod( MQTTPropBuilder_t * pPropertyBuilder, */ /* @[declare_mqttpropget_authdata] */ MQTTStatus_t MQTTPropGet_AuthData( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex, + size_t * currentIndex, const char ** pAuthData, - uint16_t * pAuthDataLen ); + size_t * pAuthDataLen ); /* @[declare_mqttpropget_authdata] */ /** @@ -2817,8 +2819,8 @@ MQTTStatus_t MQTTPropGet_AuthData( MQTTPropBuilder_t * pPropertyBuilder, */ /* @[declare_mqttpropget_payloadformatindicator] */ MQTTStatus_t MQTTPropGet_PayloadFormatIndicator( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex, - uint8_t * pPayloadFormat ); + size_t * currentIndex, + uint8_t * pPayloadFormat ); /* @[declare_mqttpropget_payloadformatindicator] */ /** @@ -2833,7 +2835,7 @@ MQTTStatus_t MQTTPropGet_PayloadFormatIndicator( MQTTPropBuilder_t * pPropertyBu */ /* @[declare_mqttpropget_messageexpiryinterval] */ MQTTStatus_t MQTTPropGet_MessageExpiryInterval( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex, + size_t * currentIndex, uint32_t * pMessageExpiry ); /* @[declare_mqttpropget_messageexpiryinterval] */ @@ -2849,7 +2851,7 @@ MQTTStatus_t MQTTPropGet_MessageExpiryInterval( MQTTPropBuilder_t * pPropertyBui */ /* @[declare_mqttpropget_topicalias] */ MQTTStatus_t MQTTPropGet_TopicAlias( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex, + size_t * currentIndex, uint16_t * pTopicAlias ); /* @[declare_mqttpropget_topicalias] */ @@ -2866,9 +2868,9 @@ MQTTStatus_t MQTTPropGet_TopicAlias( MQTTPropBuilder_t * pPropertyBuilder, */ /* @[declare_mqttpropget_responsetopic] */ MQTTStatus_t MQTTPropGet_ResponseTopic( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex, + size_t * currentIndex, const char ** pResponseTopic, - uint16_t * pResponseTopicLength ); + size_t * pResponseTopicLength ); /* @[declare_mqttpropget_responsetopic] */ /** @@ -2884,9 +2886,9 @@ MQTTStatus_t MQTTPropGet_ResponseTopic( MQTTPropBuilder_t * pPropertyBuilder, */ /* @[declare_mqttpropget_correlationdata] */ MQTTStatus_t MQTTPropGet_CorrelationData( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex, + size_t * currentIndex, const char ** pCorrelationData, - uint16_t * pCorrelationDataLength ); + size_t * pCorrelationDataLength ); /* @[declare_mqttpropget_correlationdata] */ /** @@ -2901,7 +2903,7 @@ MQTTStatus_t MQTTPropGet_CorrelationData( MQTTPropBuilder_t * pPropertyBuilder, */ /* @[declare_mqttpropget_subscriptionid] */ MQTTStatus_t MQTTPropGet_SubscriptionId( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex, + size_t * currentIndex, uint32_t * pSubscriptionId ); /* @[declare_mqttpropget_subscriptionid] */ @@ -2923,9 +2925,9 @@ MQTTStatus_t MQTTPropGet_SubscriptionId( MQTTPropBuilder_t * pPropertyBuilder, */ /* @[declare_mqttpropget_contenttype] */ MQTTStatus_t MQTTPropGet_ContentType( MQTTPropBuilder_t * pPropertyBuilder, - uint32_t * currentIndex, + size_t * currentIndex, const char ** pContentType, - uint16_t * pContentTypeLength ); + size_t * pContentTypeLength ); /* @[declare_mqttpropget_contenttype] */ /** @@ -2943,7 +2945,9 @@ MQTTStatus_t MQTTPropGet_ContentType( MQTTPropBuilder_t * pPropertyBuilder, * - #MQTTBadResponse if an invalid packet is read */ /* @[declare_mqtt_validatepublishproperties] */ -MQTTStatus_t MQTT_ValidatePublishProperties(uint16_t serverTopicAliasMax, const MQTTPropBuilder_t* propBuilder, uint16_t *topicAlias); +MQTTStatus_t MQTT_ValidatePublishProperties( uint16_t serverTopicAliasMax, + const MQTTPropBuilder_t * propBuilder, + uint16_t * topicAlias ); /* @[declare_mqtt_validatepublishproperties] */ /** @@ -2984,11 +2988,11 @@ MQTTStatus_t MQTT_ValidatePublishProperties(uint16_t serverTopicAliasMax, const * @endcode */ /* @[declare_mqtt_validatepublishparams] */ -MQTTStatus_t MQTT_ValidatePublishParams(const MQTTPublishInfo_t* pPublishInfo, - uint8_t retainAvailable, - uint8_t maxQos, - uint16_t topicAlias, - uint32_t maxPacketSize); +MQTTStatus_t MQTT_ValidatePublishParams( const MQTTPublishInfo_t * pPublishInfo, + uint8_t retainAvailable, + uint8_t maxQos, + uint16_t topicAlias, + uint32_t maxPacketSize ); /* @[declare_mqtt_validatepublishparams] */ /** @@ -3012,7 +3016,7 @@ MQTTStatus_t MQTT_ValidatePublishAckProperties( const MQTTPropBuilder_t * pPrope * - #MQTTSuccess , #MQTTBadParameter or #MQTTBadResponse. */ /* @[declare_mqtt_validateunsubscribeproperties] */ -MQTTStatus_t MQTT_ValidateUnsubscribeProperties( const MQTTPropBuilder_t * pPropertyBuilder); +MQTTStatus_t MQTT_ValidateUnsubscribeProperties( const MQTTPropBuilder_t * pPropertyBuilder ); /* @[declare_mqtt_validateunsubscribeproperties] */ /** @@ -3053,10 +3057,10 @@ MQTTStatus_t MQTT_ValidateUnsubscribeProperties( const MQTTPropBuilder_t * pProp * @endcode */ /* @[declare_mqtt_getackpacketsize] */ -MQTTStatus_t MQTT_GetAckPacketSize(size_t* pRemainingLength, - size_t* pPacketSize, - uint32_t maxPacketSize, - size_t ackPropertyLength); +MQTTStatus_t MQTT_GetAckPacketSize( uint32_t * pRemainingLength, + uint32_t * pPacketSize, + uint32_t maxPacketSize, + size_t ackPropertyLength ); /* @[declare_mqtt_getackpacketsize] */ /** @@ -3072,7 +3076,8 @@ MQTTStatus_t MQTT_GetAckPacketSize(size_t* pRemainingLength, * - #MQTTSuccess , #MQTTBadParameter or #MQTTBadResponse. */ /* @[declare_mqtt_validatedisconnectproperties] */ -MQTTStatus_t MQTT_ValidateDisconnectProperties( uint32_t connectSessionExpiry, const MQTTPropBuilder_t * pPropertyBuilder); +MQTTStatus_t MQTT_ValidateDisconnectProperties( uint32_t connectSessionExpiry, + const MQTTPropBuilder_t * pPropertyBuilder ); /* @[declare_mqtt_validatedisconnectproperties] */ /** diff --git a/source/include/private/core_mqtt_serializer_private.h b/source/include/private/core_mqtt_serializer_private.h index 27009333..596c6a4b 100644 --- a/source/include/private/core_mqtt_serializer_private.h +++ b/source/include/private/core_mqtt_serializer_private.h @@ -26,6 +26,11 @@ * @file core_mqtt_serializer_private.h * @brief Declares the private functions/macros to be used with serialization and * deserialization by the core_mqtt library. + * DO NOT include this in your application. + * + * @note These functions should not be called by the application or relied upon + * since their implementation can change. These are for internal use by the + * library only. */ #ifndef CORE_MQTT_SERIALIZER_PRIVATE_H #define CORE_MQTT_SERIALIZER_PRIVATE_H @@ -307,6 +312,32 @@ */ #define MAX_VARIABLE_LENGTH_INT_VALUE ( ( uint32_t ) 268435455U ) +/** + * @brief A macro to check whether the size_t values will overflow when converted + * to uint16_t which is used to represent MQTT UTF8 strings. + * + * Evaluates to true when the value provided will overflow 16-bit variable. False otherwise. + */ +#define CHECK_SIZE_T_OVERFLOWS_16BIT( x ) \ + ( ( sizeof( size_t ) <= sizeof( uint16_t ) ) ? false : ( ( x ) > UINT16_MAX ) ) + +/** + * @brief A macro to check whether the size_t values will overflow when converted + * to uint16_t which is used to represent MQTT UTF8 strings. + * + * Evaluates to true when the value provided will overflow 16-bit variable. False otherwise. + */ +#define CHECK_SIZE_T_OVERFLOWS_32BIT( x ) \ + ( ( sizeof( size_t ) <= sizeof( uint32_t ) ) ? false : ( ( x ) > UINT32_MAX ) ) + +/** + * @brief A macro to check whether the addition of two unsigned 32-bit numbers will overflow. + * + * Evaluates to true when the addition will overflow. False otherwise. + */ +#define ADDITION_WILL_OVERFLOW_U32( x, y ) \ + ( ( x ) > ( UINT32_MAX - ( y ) ) ) + /** * @fn size_t variableLengthEncodedSize( uint32_t length ); * @@ -346,7 +377,7 @@ uint8_t * encodeString( uint8_t * pDestination, /** @endcond */ /** - * @fn MQTTStatus_t decodeUserProp( const char ** pPropertyKey, uint16_t * pPropertyKeyLen, const char ** pPropertyValue, uint16_t * pPropertyValueLen, uint32_t * pPropertyLength, uint8_t ** pIndex ); + * @fn MQTTStatus_t decodeUserProp( const char ** pPropertyKey, size_t * pPropertyKeyLen, const char ** pPropertyValue, size_t * pPropertyValueLen, uint32_t * pPropertyLength, uint8_t ** pIndex ); * * @brief Validate the length and decode a user property. * @@ -365,9 +396,9 @@ uint8_t * encodeString( uint8_t * pDestination, * Doxygen should ignore this definition, this function is private. */ MQTTStatus_t decodeUserProp( const char ** pPropertyKey, - uint16_t * pPropertyKeyLen, + size_t * pPropertyKeyLen, const char ** pPropertyValue, - uint16_t * pPropertyValueLen, + size_t * pPropertyValueLen, uint32_t * pPropertyLength, uint8_t ** pIndex ); /** @endcond */ @@ -463,7 +494,7 @@ uint8_t * encodeVariableLength( uint8_t * pDestination, /** @endcond */ /** - * @fn MQTTStatus_t decodeUtf8( const char ** pProperty, uint16_t * pLength, uint32_t * pPropertyLength, bool * pUsed, uint8_t ** pIndex ); + * @fn MQTTStatus_t decodeUtf8( const char ** pProperty, size_t * pLength, uint32_t * pPropertyLength, bool * pUsed, uint8_t ** pIndex ); * * @brief Validate the length and decode a utf 8 string. * @@ -481,7 +512,7 @@ uint8_t * encodeVariableLength( uint8_t * pDestination, * Doxygen should ignore this definition, this function is private. */ MQTTStatus_t decodeUtf8( const char ** pProperty, - uint16_t * pLength, + size_t * pLength, uint32_t * pPropertyLength, bool * pUsed, uint8_t ** pIndex ); @@ -511,7 +542,7 @@ MQTTStatus_t decodeVariableLength( const uint8_t * pBuffer, /** @endcond */ /** - * @fn uint8_t * serializeAckFixed( uint8_t * pIndex, uint8_t packetType, uint16_t packetId, size_t remainingLength, MQTTSuccessFailReasonCode_t reasonCode ); + * @fn uint8_t * serializeAckFixed( uint8_t * pIndex, uint8_t packetType, uint16_t packetId, uint32_t remainingLength, MQTTSuccessFailReasonCode_t reasonCode ); * * @brief Serialize the fixed size part of the ack packet header. * @@ -532,7 +563,7 @@ MQTTStatus_t decodeVariableLength( const uint8_t * pBuffer, uint8_t * serializeAckFixed( uint8_t * pIndex, uint8_t packetType, uint16_t packetId, - size_t remainingLength, + uint32_t remainingLength, MQTTSuccessFailReasonCode_t reasonCode ); /** @endcond */ @@ -559,7 +590,7 @@ MQTTStatus_t decodeSubackPropertyLength( const uint8_t * pIndex, /** @endcond */ /** - * @fn uint8_t * serializeDisconnectFixed( uint8_t * pIndex, MQTTSuccessFailReasonCode_t * pReasonCode, size_t remainingLength ); + * @fn uint8_t * serializeDisconnectFixed( uint8_t * pIndex, MQTTSuccessFailReasonCode_t * pReasonCode, uint32_t remainingLength ); * * @brief Serialize the fixed size part of the disconnect packet header. * @@ -576,7 +607,7 @@ MQTTStatus_t decodeSubackPropertyLength( const uint8_t * pIndex, */ uint8_t * serializeDisconnectFixed( uint8_t * pIndex, MQTTSuccessFailReasonCode_t * pReasonCode, - size_t remainingLength ); + uint32_t remainingLength ); /** @endcond */ /** @@ -604,7 +635,7 @@ uint8_t * serializeConnectFixedHeader( uint8_t * pIndex, /** @endcond */ /** - * @fn uint8_t * serializeSubscribeHeader( size_t remainingLength, uint8_t * pIndex, uint16_t packetId ); + * @fn uint8_t * serializeSubscribeHeader( uint32_t remainingLength, uint8_t * pIndex, uint16_t packetId ); * @brief Serialize the fixed part of the subscribe packet header. * * @param[in] remainingLength The remaining length of the packet to be @@ -620,13 +651,13 @@ uint8_t * serializeConnectFixedHeader( uint8_t * pIndex, * @cond DOXYGEN_IGNORE * Doxygen should ignore this definition, this function is private. */ -uint8_t * serializeSubscribeHeader( size_t remainingLength, +uint8_t * serializeSubscribeHeader( uint32_t remainingLength, uint8_t * pIndex, uint16_t packetId ); /** @endcond */ /** - * @fn uint8_t * serializeUnsubscribeHeader( size_t remainingLength, uint8_t * pIndex, uint16_t packetId ); + * @fn uint8_t * serializeUnsubscribeHeader( uint32_t remainingLength, uint8_t * pIndex, uint16_t packetId ); * @brief Serialize the fixed part of the unsubscribe packet header. * * @param[in] remainingLength The remaining length of the packet to be @@ -642,7 +673,7 @@ uint8_t * serializeSubscribeHeader( size_t remainingLength, * @cond DOXYGEN_IGNORE * Doxygen should ignore this definition, this function is private. */ -uint8_t * serializeUnsubscribeHeader( size_t remainingLength, +uint8_t * serializeUnsubscribeHeader( uint32_t remainingLength, uint8_t * pIndex, uint16_t packetId ); /** @endcond */ diff --git a/test/cbmc/proofs/DecodePubAckProperties/DecodePubAckProperties_harness.c b/test/cbmc/proofs/DecodePubAckProperties/DecodePubAckProperties_harness.c index 9128e074..d657427a 100644 --- a/test/cbmc/proofs/DecodePubAckProperties/DecodePubAckProperties_harness.c +++ b/test/cbmc/proofs/DecodePubAckProperties/DecodePubAckProperties_harness.c @@ -51,7 +51,7 @@ void harness() { MQTTPropBuilder_t * propBuffer; uint8_t * packetBytes; - size_t remainingLength; + uint32_t remainingLength; size_t propertyLength; propBuffer = allocateMqttPropBuilder( NULL ); diff --git a/test/cbmc/proofs/DeserializeHelpers/DeserializeHelpers_harness.c b/test/cbmc/proofs/DeserializeHelpers/DeserializeHelpers_harness.c index 9e66c48f..9bea5ddd 100644 --- a/test/cbmc/proofs/DeserializeHelpers/DeserializeHelpers_harness.c +++ b/test/cbmc/proofs/DeserializeHelpers/DeserializeHelpers_harness.c @@ -64,7 +64,7 @@ void harness() __CPROVER_assume( *buffer != NULL ); const char * pPropertyKey, * pPropertyValue; - uint16_t PropertyKeyLen, PropertyValueLen; + size_t PropertyKeyLen, PropertyValueLen; decodeUserProp( &pPropertyKey, &PropertyKeyLen, @@ -97,7 +97,7 @@ void harness() __CPROVER_assume( *buffer != NULL ); const char * pProperty; - uint16_t PropertyLen; + size_t PropertyLen; decodeUtf8( &pProperty, &PropertyLen, length, diff --git a/test/cbmc/proofs/DeserializePublishProperties/DeserializePublishProperties_harness.c b/test/cbmc/proofs/DeserializePublishProperties/DeserializePublishProperties_harness.c index dd7157c1..307de867 100644 --- a/test/cbmc/proofs/DeserializePublishProperties/DeserializePublishProperties_harness.c +++ b/test/cbmc/proofs/DeserializePublishProperties/DeserializePublishProperties_harness.c @@ -54,12 +54,13 @@ void harness() size_t propertyLength; size_t maxPropertyLength; size_t minRemainingLength; - size_t remainingLength; + uint32_t remainingLength; pPublishInfo = allocateMqttPublishInfo( NULL ); __CPROVER_assume( isValidMqttPublishInfo( pPublishInfo ) ); __CPROVER_assume( pPublishInfo != NULL ); __CPROVER_assume( pPublishInfo->topicNameLength != 0 ); + __CPROVER_assume( pPublishInfo->topicNameLength <= UINT16_MAX ); propBuffer = allocateMqttPropBuilder( NULL ); __CPROVER_assume( isValidMqttPropBuilder( propBuffer ) ); diff --git a/test/cbmc/proofs/MQTTPropGet_AssignedClientId/MQTTPropGet_AssignedClientId_harness.c b/test/cbmc/proofs/MQTTPropGet_AssignedClientId/MQTTPropGet_AssignedClientId_harness.c index 91db8ba1..77ec0de9 100644 --- a/test/cbmc/proofs/MQTTPropGet_AssignedClientId/MQTTPropGet_AssignedClientId_harness.c +++ b/test/cbmc/proofs/MQTTPropGet_AssignedClientId/MQTTPropGet_AssignedClientId_harness.c @@ -33,8 +33,8 @@ void harness() { MQTTPropBuilder_t * propBuffer; char ** pClientId; - uint16_t * clientIdLength; - uint32_t currentIndex; + size_t * clientIdLength; + size_t currentIndex; propBuffer = allocateMqttPropBuilder( NULL ); __CPROVER_assume( isValidMqttPropBuilder( propBuffer ) ); @@ -47,7 +47,7 @@ void harness() } pClientId = malloc( sizeof( char * ) ); - clientIdLength = malloc( sizeof( uint16_t ) ); + clientIdLength = malloc( sizeof( size_t ) ); MQTTPropGet_AssignedClientId( propBuffer, ¤tIndex, pClientId, clientIdLength ); } diff --git a/test/cbmc/proofs/MQTTPropGet_AuthData/MQTTPropGet_AuthData_harness.c b/test/cbmc/proofs/MQTTPropGet_AuthData/MQTTPropGet_AuthData_harness.c index d14e6f28..3d94372c 100644 --- a/test/cbmc/proofs/MQTTPropGet_AuthData/MQTTPropGet_AuthData_harness.c +++ b/test/cbmc/proofs/MQTTPropGet_AuthData/MQTTPropGet_AuthData_harness.c @@ -33,8 +33,8 @@ void harness() { MQTTPropBuilder_t * propBuffer; char ** pAuthData; - uint16_t * authDataLength; - uint32_t currentIndex; + size_t * authDataLength; + size_t currentIndex; propBuffer = allocateMqttPropBuilder( NULL ); __CPROVER_assume( isValidMqttPropBuilder( propBuffer ) ); @@ -47,7 +47,7 @@ void harness() } pAuthData = malloc( sizeof( char * ) ); - authDataLength = malloc( sizeof( uint16_t ) ); + authDataLength = malloc( sizeof( size_t ) ); MQTTPropGet_AuthData( propBuffer, ¤tIndex, pAuthData, authDataLength ); } diff --git a/test/cbmc/proofs/MQTTPropGet_AuthMethod/MQTTPropGet_AuthMethod_harness.c b/test/cbmc/proofs/MQTTPropGet_AuthMethod/MQTTPropGet_AuthMethod_harness.c index 5c8ff132..4e0708f6 100644 --- a/test/cbmc/proofs/MQTTPropGet_AuthMethod/MQTTPropGet_AuthMethod_harness.c +++ b/test/cbmc/proofs/MQTTPropGet_AuthMethod/MQTTPropGet_AuthMethod_harness.c @@ -33,8 +33,8 @@ void harness() { MQTTPropBuilder_t * propBuffer; char ** pAuthMethod; - uint16_t * authMethodLength; - uint32_t currentIndex; + size_t * authMethodLength; + size_t currentIndex; propBuffer = allocateMqttPropBuilder( NULL ); __CPROVER_assume( isValidMqttPropBuilder( propBuffer ) ); @@ -47,7 +47,7 @@ void harness() } pAuthMethod = malloc( sizeof( char * ) ); - authMethodLength = malloc( sizeof( uint16_t ) ); + authMethodLength = malloc( sizeof( size_t ) ); MQTTPropGet_AuthMethod( propBuffer, ¤tIndex, pAuthMethod, authMethodLength ); } diff --git a/test/cbmc/proofs/MQTTPropGet_ContentType/MQTTPropGet_ContentType_harness.c b/test/cbmc/proofs/MQTTPropGet_ContentType/MQTTPropGet_ContentType_harness.c index f80e0364..b4f5c709 100644 --- a/test/cbmc/proofs/MQTTPropGet_ContentType/MQTTPropGet_ContentType_harness.c +++ b/test/cbmc/proofs/MQTTPropGet_ContentType/MQTTPropGet_ContentType_harness.c @@ -33,8 +33,8 @@ void harness() { MQTTPropBuilder_t * propBuffer; char ** pContentType; - uint16_t * contentTypeLength; - uint32_t currentIndex; + size_t * contentTypeLength; + size_t currentIndex; propBuffer = allocateMqttPropBuilder( NULL ); __CPROVER_assume( isValidMqttPropBuilder( propBuffer ) ); @@ -47,7 +47,7 @@ void harness() } pContentType = malloc( sizeof( char * ) ); - contentTypeLength = malloc( sizeof( uint16_t ) ); + contentTypeLength = malloc( sizeof( size_t ) ); MQTTPropGet_ContentType( propBuffer, ¤tIndex, pContentType, contentTypeLength ); } diff --git a/test/cbmc/proofs/MQTTPropGet_CorrelationData/MQTTPropGet_CorrelationData_harness.c b/test/cbmc/proofs/MQTTPropGet_CorrelationData/MQTTPropGet_CorrelationData_harness.c index f40c06ce..639b4cc3 100644 --- a/test/cbmc/proofs/MQTTPropGet_CorrelationData/MQTTPropGet_CorrelationData_harness.c +++ b/test/cbmc/proofs/MQTTPropGet_CorrelationData/MQTTPropGet_CorrelationData_harness.c @@ -33,8 +33,8 @@ void harness() { MQTTPropBuilder_t * propBuffer; char ** correlationData; - uint16_t * correlationLength; - uint32_t currentIndex; + size_t * correlationLength; + size_t currentIndex; propBuffer = allocateMqttPropBuilder( NULL ); __CPROVER_assume( isValidMqttPropBuilder( propBuffer ) ); @@ -47,7 +47,7 @@ void harness() } correlationData = malloc( sizeof( char * ) ); - correlationLength = malloc( sizeof( uint16_t ) ); + correlationLength = malloc( sizeof( size_t ) ); MQTTPropGet_CorrelationData( propBuffer, ¤tIndex, correlationData, correlationLength ); } diff --git a/test/cbmc/proofs/MQTTPropGet_MaxPacketSize/MQTTPropGet_MaxPacketSize_harness.c b/test/cbmc/proofs/MQTTPropGet_MaxPacketSize/MQTTPropGet_MaxPacketSize_harness.c index 789a15b6..d64ad0d2 100644 --- a/test/cbmc/proofs/MQTTPropGet_MaxPacketSize/MQTTPropGet_MaxPacketSize_harness.c +++ b/test/cbmc/proofs/MQTTPropGet_MaxPacketSize/MQTTPropGet_MaxPacketSize_harness.c @@ -33,7 +33,7 @@ void harness() { MQTTPropBuilder_t * propBuffer; uint32_t * maxPacketSize; - uint32_t currentIndex; + size_t currentIndex; propBuffer = allocateMqttPropBuilder( NULL ); __CPROVER_assume( isValidMqttPropBuilder( propBuffer ) ); diff --git a/test/cbmc/proofs/MQTTPropGet_MaxQos/MQTTPropGet_MaxQos_harness.c b/test/cbmc/proofs/MQTTPropGet_MaxQos/MQTTPropGet_MaxQos_harness.c index 0fd5a7bf..5fc11921 100644 --- a/test/cbmc/proofs/MQTTPropGet_MaxQos/MQTTPropGet_MaxQos_harness.c +++ b/test/cbmc/proofs/MQTTPropGet_MaxQos/MQTTPropGet_MaxQos_harness.c @@ -33,7 +33,7 @@ void harness() { MQTTPropBuilder_t * propBuffer; uint8_t * maxQos; - uint32_t currentIndex; + size_t currentIndex; propBuffer = allocateMqttPropBuilder( NULL ); __CPROVER_assume( isValidMqttPropBuilder( propBuffer ) ); diff --git a/test/cbmc/proofs/MQTTPropGet_MessageExpiryInterval/MQTTPropGet_MessageExpiryInterval_harness.c b/test/cbmc/proofs/MQTTPropGet_MessageExpiryInterval/MQTTPropGet_MessageExpiryInterval_harness.c index 451e22b2..2367bc0d 100644 --- a/test/cbmc/proofs/MQTTPropGet_MessageExpiryInterval/MQTTPropGet_MessageExpiryInterval_harness.c +++ b/test/cbmc/proofs/MQTTPropGet_MessageExpiryInterval/MQTTPropGet_MessageExpiryInterval_harness.c @@ -33,7 +33,7 @@ void harness() { MQTTPropBuilder_t * propBuffer; uint32_t * msgExpiryInterval; - uint32_t currentIndex; + size_t currentIndex; propBuffer = allocateMqttPropBuilder( NULL ); __CPROVER_assume( isValidMqttPropBuilder( propBuffer ) ); diff --git a/test/cbmc/proofs/MQTTPropGet_PayloadFormatIndicator/MQTTPropGet_PayloadFormatIndicator_harness.c b/test/cbmc/proofs/MQTTPropGet_PayloadFormatIndicator/MQTTPropGet_PayloadFormatIndicator_harness.c index 4dc32191..4434a178 100644 --- a/test/cbmc/proofs/MQTTPropGet_PayloadFormatIndicator/MQTTPropGet_PayloadFormatIndicator_harness.c +++ b/test/cbmc/proofs/MQTTPropGet_PayloadFormatIndicator/MQTTPropGet_PayloadFormatIndicator_harness.c @@ -33,7 +33,7 @@ void harness() { MQTTPropBuilder_t * propBuffer; uint8_t * payloadFormat; - uint32_t currentIndex; + size_t currentIndex; propBuffer = allocateMqttPropBuilder( NULL ); __CPROVER_assume( isValidMqttPropBuilder( propBuffer ) ); diff --git a/test/cbmc/proofs/MQTTPropGet_ReasonString/MQTTPropGet_ReasonString_harness.c b/test/cbmc/proofs/MQTTPropGet_ReasonString/MQTTPropGet_ReasonString_harness.c index b3e9d6d8..1b546c07 100644 --- a/test/cbmc/proofs/MQTTPropGet_ReasonString/MQTTPropGet_ReasonString_harness.c +++ b/test/cbmc/proofs/MQTTPropGet_ReasonString/MQTTPropGet_ReasonString_harness.c @@ -34,7 +34,7 @@ void harness() MQTTPropBuilder_t * propBuffer; char ** pReasonString; uint16_t * reasonStringLength; - uint32_t currentIndex; + size_t currentIndex; propBuffer = allocateMqttPropBuilder( NULL ); __CPROVER_assume( isValidMqttPropBuilder( propBuffer ) ); diff --git a/test/cbmc/proofs/MQTTPropGet_ReceiveMax/MQTTPropGet_ReceiveMax_harness.c b/test/cbmc/proofs/MQTTPropGet_ReceiveMax/MQTTPropGet_ReceiveMax_harness.c index be15ef6e..51bbd9dc 100644 --- a/test/cbmc/proofs/MQTTPropGet_ReceiveMax/MQTTPropGet_ReceiveMax_harness.c +++ b/test/cbmc/proofs/MQTTPropGet_ReceiveMax/MQTTPropGet_ReceiveMax_harness.c @@ -33,7 +33,7 @@ void harness() { MQTTPropBuilder_t * propBuffer; uint16_t * receiveMax; - uint32_t currentIndex; + size_t currentIndex; propBuffer = allocateMqttPropBuilder( NULL ); __CPROVER_assume( isValidMqttPropBuilder( propBuffer ) ); diff --git a/test/cbmc/proofs/MQTTPropGet_ResponseInfo/MQTTPropGet_ResponseInfo_harness.c b/test/cbmc/proofs/MQTTPropGet_ResponseInfo/MQTTPropGet_ResponseInfo_harness.c index 48ccd0e4..8c51d211 100644 --- a/test/cbmc/proofs/MQTTPropGet_ResponseInfo/MQTTPropGet_ResponseInfo_harness.c +++ b/test/cbmc/proofs/MQTTPropGet_ResponseInfo/MQTTPropGet_ResponseInfo_harness.c @@ -34,7 +34,7 @@ void harness() MQTTPropBuilder_t * propBuffer; char ** pResponseInfo; uint16_t * responseInfoLength; - uint32_t currentIndex; + size_t currentIndex; propBuffer = allocateMqttPropBuilder( NULL ); __CPROVER_assume( isValidMqttPropBuilder( propBuffer ) ); @@ -47,7 +47,7 @@ void harness() } pResponseInfo = malloc( sizeof( char * ) ); - responseInfoLength = malloc( sizeof( uint16_t ) ); + responseInfoLength = malloc( sizeof( size_t ) ); MQTTPropGet_ResponseInfo( propBuffer, ¤tIndex, pResponseInfo, responseInfoLength ); } diff --git a/test/cbmc/proofs/MQTTPropGet_ResponseTopic/MQTTPropGet_ResponseTopic_harness.c b/test/cbmc/proofs/MQTTPropGet_ResponseTopic/MQTTPropGet_ResponseTopic_harness.c index af5cbb22..854048db 100644 --- a/test/cbmc/proofs/MQTTPropGet_ResponseTopic/MQTTPropGet_ResponseTopic_harness.c +++ b/test/cbmc/proofs/MQTTPropGet_ResponseTopic/MQTTPropGet_ResponseTopic_harness.c @@ -34,7 +34,7 @@ void harness() MQTTPropBuilder_t * propBuffer; char ** responseTopic; uint16_t * responseTopicLength; - uint32_t currentIndex; + size_t currentIndex; propBuffer = allocateMqttPropBuilder( NULL ); __CPROVER_assume( isValidMqttPropBuilder( propBuffer ) ); @@ -47,7 +47,7 @@ void harness() } responseTopic = malloc( sizeof( char * ) ); - responseTopicLength = malloc( sizeof( uint16_t ) ); + responseTopicLength = malloc( sizeof( size_t ) ); MQTTPropGet_ResponseTopic( propBuffer, ¤tIndex, responseTopic, responseTopicLength ); } diff --git a/test/cbmc/proofs/MQTTPropGet_RetainAvailable/MQTTPropGet_RetainAvailable_harness.c b/test/cbmc/proofs/MQTTPropGet_RetainAvailable/MQTTPropGet_RetainAvailable_harness.c index ed07d7a4..e089cf14 100644 --- a/test/cbmc/proofs/MQTTPropGet_RetainAvailable/MQTTPropGet_RetainAvailable_harness.c +++ b/test/cbmc/proofs/MQTTPropGet_RetainAvailable/MQTTPropGet_RetainAvailable_harness.c @@ -33,7 +33,7 @@ void harness() { MQTTPropBuilder_t * propBuffer; uint8_t * retainAvailable; - uint32_t currentIndex; + size_t currentIndex; propBuffer = allocateMqttPropBuilder( NULL ); __CPROVER_assume( isValidMqttPropBuilder( propBuffer ) ); diff --git a/test/cbmc/proofs/MQTTPropGet_ServerKeepAlive/MQTTPropGet_ServerKeepAlive_harness.c b/test/cbmc/proofs/MQTTPropGet_ServerKeepAlive/MQTTPropGet_ServerKeepAlive_harness.c index 0bd96701..0004c1ae 100644 --- a/test/cbmc/proofs/MQTTPropGet_ServerKeepAlive/MQTTPropGet_ServerKeepAlive_harness.c +++ b/test/cbmc/proofs/MQTTPropGet_ServerKeepAlive/MQTTPropGet_ServerKeepAlive_harness.c @@ -33,7 +33,7 @@ void harness() { MQTTPropBuilder_t * propBuffer; uint16_t * serverKeepAlive; - uint32_t currentIndex; + size_t currentIndex; propBuffer = allocateMqttPropBuilder( NULL ); __CPROVER_assume( isValidMqttPropBuilder( propBuffer ) ); diff --git a/test/cbmc/proofs/MQTTPropGet_ServerRef/MQTTPropGet_ServerRef_harness.c b/test/cbmc/proofs/MQTTPropGet_ServerRef/MQTTPropGet_ServerRef_harness.c index ddf487e0..d61e71c0 100644 --- a/test/cbmc/proofs/MQTTPropGet_ServerRef/MQTTPropGet_ServerRef_harness.c +++ b/test/cbmc/proofs/MQTTPropGet_ServerRef/MQTTPropGet_ServerRef_harness.c @@ -34,7 +34,7 @@ void harness() MQTTPropBuilder_t * propBuffer; char ** pServerRef; uint16_t * serverRefLength; - uint32_t currentIndex; + size_t currentIndex; propBuffer = allocateMqttPropBuilder( NULL ); __CPROVER_assume( isValidMqttPropBuilder( propBuffer ) ); diff --git a/test/cbmc/proofs/MQTTPropGet_SessionExpiry/MQTTPropGet_SessionExpiry_harness.c b/test/cbmc/proofs/MQTTPropGet_SessionExpiry/MQTTPropGet_SessionExpiry_harness.c index 5e63026b..40686f8c 100644 --- a/test/cbmc/proofs/MQTTPropGet_SessionExpiry/MQTTPropGet_SessionExpiry_harness.c +++ b/test/cbmc/proofs/MQTTPropGet_SessionExpiry/MQTTPropGet_SessionExpiry_harness.c @@ -33,7 +33,7 @@ void harness() { MQTTPropBuilder_t * propBuffer; uint32_t * sessionExpiry; - uint32_t currentIndex; + size_t currentIndex; propBuffer = allocateMqttPropBuilder( NULL ); __CPROVER_assume( isValidMqttPropBuilder( propBuffer ) ); diff --git a/test/cbmc/proofs/MQTTPropGet_SharedSubAvailable/MQTTPropGet_SharedSubAvailable_harness.c b/test/cbmc/proofs/MQTTPropGet_SharedSubAvailable/MQTTPropGet_SharedSubAvailable_harness.c index 6df0748b..97f20f95 100644 --- a/test/cbmc/proofs/MQTTPropGet_SharedSubAvailable/MQTTPropGet_SharedSubAvailable_harness.c +++ b/test/cbmc/proofs/MQTTPropGet_SharedSubAvailable/MQTTPropGet_SharedSubAvailable_harness.c @@ -33,7 +33,7 @@ void harness() { MQTTPropBuilder_t * propBuffer; uint8_t * isSharedSubAvailable; - uint32_t currentIndex; + size_t currentIndex; propBuffer = allocateMqttPropBuilder( NULL ); __CPROVER_assume( isValidMqttPropBuilder( propBuffer ) ); diff --git a/test/cbmc/proofs/MQTTPropGet_SubsIdAvailable/MQTTPropGet_SubsIdAvailable_harness.c b/test/cbmc/proofs/MQTTPropGet_SubsIdAvailable/MQTTPropGet_SubsIdAvailable_harness.c index 53718d21..17481a26 100644 --- a/test/cbmc/proofs/MQTTPropGet_SubsIdAvailable/MQTTPropGet_SubsIdAvailable_harness.c +++ b/test/cbmc/proofs/MQTTPropGet_SubsIdAvailable/MQTTPropGet_SubsIdAvailable_harness.c @@ -33,7 +33,7 @@ void harness() { MQTTPropBuilder_t * propBuffer; uint8_t * isSubIdAvailable; - uint32_t currentIndex; + size_t currentIndex; propBuffer = allocateMqttPropBuilder( NULL ); __CPROVER_assume( isValidMqttPropBuilder( propBuffer ) ); diff --git a/test/cbmc/proofs/MQTTPropGet_SubscriptionId/MQTTPropGet_SubscriptionId_harness.c b/test/cbmc/proofs/MQTTPropGet_SubscriptionId/MQTTPropGet_SubscriptionId_harness.c index a6f53fa0..5109f271 100644 --- a/test/cbmc/proofs/MQTTPropGet_SubscriptionId/MQTTPropGet_SubscriptionId_harness.c +++ b/test/cbmc/proofs/MQTTPropGet_SubscriptionId/MQTTPropGet_SubscriptionId_harness.c @@ -33,7 +33,7 @@ void harness() { MQTTPropBuilder_t * propBuffer; size_t * subscriptionId; - uint32_t currentIndex; + size_t currentIndex; propBuffer = allocateMqttPropBuilder( NULL ); __CPROVER_assume( isValidMqttPropBuilder( propBuffer ) ); diff --git a/test/cbmc/proofs/MQTTPropGet_TopicAlias/MQTTPropGet_TopicAlias_harness.c b/test/cbmc/proofs/MQTTPropGet_TopicAlias/MQTTPropGet_TopicAlias_harness.c index 33d0b0e0..e4ad7d1e 100644 --- a/test/cbmc/proofs/MQTTPropGet_TopicAlias/MQTTPropGet_TopicAlias_harness.c +++ b/test/cbmc/proofs/MQTTPropGet_TopicAlias/MQTTPropGet_TopicAlias_harness.c @@ -33,7 +33,7 @@ void harness() { MQTTPropBuilder_t * propBuffer; uint16_t * topicAlias; - uint32_t currentIndex; + size_t currentIndex; propBuffer = allocateMqttPropBuilder( NULL ); __CPROVER_assume( isValidMqttPropBuilder( propBuffer ) ); diff --git a/test/cbmc/proofs/MQTTPropGet_TopicAliasMax/MQTTPropGet_TopicAliasMax_harness.c b/test/cbmc/proofs/MQTTPropGet_TopicAliasMax/MQTTPropGet_TopicAliasMax_harness.c index 34f4bc61..2d0bdbc7 100644 --- a/test/cbmc/proofs/MQTTPropGet_TopicAliasMax/MQTTPropGet_TopicAliasMax_harness.c +++ b/test/cbmc/proofs/MQTTPropGet_TopicAliasMax/MQTTPropGet_TopicAliasMax_harness.c @@ -33,7 +33,7 @@ void harness() { MQTTPropBuilder_t * propBuffer; uint16_t * topicAliasMax; - uint32_t currentIndex; + size_t currentIndex; propBuffer = allocateMqttPropBuilder( NULL ); __CPROVER_assume( isValidMqttPropBuilder( propBuffer ) ); diff --git a/test/cbmc/proofs/MQTTPropGet_UserProp/MQTTPropGet_UserProp_harness.c b/test/cbmc/proofs/MQTTPropGet_UserProp/MQTTPropGet_UserProp_harness.c index 2776ea40..d97c498b 100644 --- a/test/cbmc/proofs/MQTTPropGet_UserProp/MQTTPropGet_UserProp_harness.c +++ b/test/cbmc/proofs/MQTTPropGet_UserProp/MQTTPropGet_UserProp_harness.c @@ -32,7 +32,7 @@ void harness() { MQTTPropBuilder_t * propBuffer; - uint32_t currentIndex; + size_t currentIndex; MQTTUserProperty_t pUserProperty; propBuffer = allocateMqttPropBuilder( NULL ); diff --git a/test/cbmc/proofs/MQTTPropGet_WildcardId/MQTTPropGet_WildcardId_harness.c b/test/cbmc/proofs/MQTTPropGet_WildcardId/MQTTPropGet_WildcardId_harness.c index 1bfb81d4..4b9a6c72 100644 --- a/test/cbmc/proofs/MQTTPropGet_WildcardId/MQTTPropGet_WildcardId_harness.c +++ b/test/cbmc/proofs/MQTTPropGet_WildcardId/MQTTPropGet_WildcardId_harness.c @@ -33,7 +33,7 @@ void harness() { MQTTPropBuilder_t * propBuffer; uint8_t * isWildCardAvailable; - uint32_t currentIndex; + size_t currentIndex; propBuffer = allocateMqttPropBuilder( NULL ); __CPROVER_assume( isValidMqttPropBuilder( propBuffer ) ); diff --git a/test/cbmc/proofs/MQTT_Connect/MQTT_Connect_harness.c b/test/cbmc/proofs/MQTT_Connect/MQTT_Connect_harness.c index 7f31b945..df362f93 100644 --- a/test/cbmc/proofs/MQTT_Connect/MQTT_Connect_harness.c +++ b/test/cbmc/proofs/MQTT_Connect/MQTT_Connect_harness.c @@ -63,7 +63,7 @@ static uint32_t ulGetTimeFunction( void ) uint8_t * serializeConnectFixedHeader( uint8_t * pIndex, const MQTTConnectInfo_t * pConnectInfo, const MQTTPublishInfo_t * pWillInfo, - size_t remainingLength ) + uint32_t remainingLength ) { __CPROVER_assert( pIndex != NULL, "pIndex must not be NULL." ); __CPROVER_assert( pConnectInfo != NULL, "pConnectInfo must not be NULL." ); diff --git a/test/cbmc/proofs/MQTT_DeserializeAck/MQTT_DeserializeAck_harness.c b/test/cbmc/proofs/MQTT_DeserializeAck/MQTT_DeserializeAck_harness.c index 043fdc3b..62c79bbf 100644 --- a/test/cbmc/proofs/MQTT_DeserializeAck/MQTT_DeserializeAck_harness.c +++ b/test/cbmc/proofs/MQTT_DeserializeAck/MQTT_DeserializeAck_harness.c @@ -42,7 +42,7 @@ MQTTStatus_t __CPROVER_file_local_core_mqtt_serializer_c_deserializeConnackPrope MQTTStatus_t __CPROVER_file_local_core_mqtt_serializer_c_deserializeSubUnsubAckProperties( MQTTPropBuilder_t * propBuffer, uint8_t * pIndex, size_t * pSubackPropertyLength, - size_t remainingLength ) + uint32_t remainingLength ) { MQTTStatus_t status; @@ -51,7 +51,7 @@ MQTTStatus_t __CPROVER_file_local_core_mqtt_serializer_c_deserializeSubUnsubAckP MQTTStatus_t __CPROVER_file_local_core_mqtt_serializer_c_decodePubAckProperties( MQTTPropBuilder_t * propBuffer, uint8_t * pIndex, - size_t remainingLength ) + uint32_t remainingLength ) { MQTTStatus_t status; diff --git a/test/cbmc/proofs/MQTT_DeserializePublish/MQTT_DeserializePublish_harness.c b/test/cbmc/proofs/MQTT_DeserializePublish/MQTT_DeserializePublish_harness.c index 5998aa65..f3ca9021 100644 --- a/test/cbmc/proofs/MQTT_DeserializePublish/MQTT_DeserializePublish_harness.c +++ b/test/cbmc/proofs/MQTT_DeserializePublish/MQTT_DeserializePublish_harness.c @@ -35,12 +35,12 @@ MQTTStatus_t __CPROVER_file_local_core_mqtt_serializer_c_deserializePublishPrope MQTTPropBuilder_t * propBuffer, uint8_t * pIndex, uint16_t topicAliasMax, - size_t remainingLength ) + uint32_t remainingLength ) { MQTTStatus_t status; size_t propertyLength = 0U; uint8_t * pLocalIndex = pIndex; - size_t remainingLengthForProperties; + uint32_t remainingLengthForProperties; remainingLengthForProperties = remainingLength; remainingLengthForProperties -= pPublishInfo->topicNameLength + sizeof( uint16_t ); diff --git a/test/cbmc/proofs/MQTT_GetNextPropertyType/MQTT_GetNextPropertyType_harness.c b/test/cbmc/proofs/MQTT_GetNextPropertyType/MQTT_GetNextPropertyType_harness.c index c3388978..5541b894 100644 --- a/test/cbmc/proofs/MQTT_GetNextPropertyType/MQTT_GetNextPropertyType_harness.c +++ b/test/cbmc/proofs/MQTT_GetNextPropertyType/MQTT_GetNextPropertyType_harness.c @@ -34,7 +34,7 @@ void harness() { MQTTPropBuilder_t * propBuffer; uint8_t * propertyId; - uint32_t * currentIndex = malloc( sizeof( uint32_t ) ); + size_t * currentIndex = malloc( sizeof( size_t ) ); propBuffer = allocateMqttPropBuilder( NULL ); __CPROVER_assume( isValidMqttPropBuilder( propBuffer ) ); diff --git a/test/cbmc/proofs/MQTT_ProcessLoop/MQTT_ProcessLoop_harness.c b/test/cbmc/proofs/MQTT_ProcessLoop/MQTT_ProcessLoop_harness.c index 5ff3c296..0703f0fa 100644 --- a/test/cbmc/proofs/MQTT_ProcessLoop/MQTT_ProcessLoop_harness.c +++ b/test/cbmc/proofs/MQTT_ProcessLoop/MQTT_ProcessLoop_harness.c @@ -54,7 +54,7 @@ MQTTStatus_t MQTT_DeserializePublish( const MQTTPacketInfo_t * pIncomingPacket, MQTTStatus_t MQTT_SerializeDisconnect( const MQTTPropBuilder_t * pDisconnectProperties, MQTTSuccessFailReasonCode_t * pReasonCode, - size_t remainingLength, + uint32_t remainingLength, const MQTTFixedBuffer_t * pFixedBuffer ) { MQTTStatus_t result; @@ -73,8 +73,8 @@ MQTTStatus_t MQTT_DeserializeDisconnect( const MQTTPacketInfo_t * pPacket, } MQTTStatus_t MQTT_GetDisconnectPacketSize( const MQTTPropBuilder_t * pDisconnectProperties, - size_t * pRemainingLength, - size_t * pPacketSize, + uint32_t * pRemainingLength, + uint32_t * pPacketSize, uint32_t maxPacketSize, MQTTSuccessFailReasonCode_t * pReasonCode ) { diff --git a/test/cbmc/proofs/MQTT_ReceiveLoop/MQTT_ReceiveLoop_harness.c b/test/cbmc/proofs/MQTT_ReceiveLoop/MQTT_ReceiveLoop_harness.c index 5a5be04c..97e75665 100644 --- a/test/cbmc/proofs/MQTT_ReceiveLoop/MQTT_ReceiveLoop_harness.c +++ b/test/cbmc/proofs/MQTT_ReceiveLoop/MQTT_ReceiveLoop_harness.c @@ -54,7 +54,7 @@ MQTTStatus_t MQTT_DeserializePublish( const MQTTPacketInfo_t * pIncomingPacket, MQTTStatus_t MQTT_SerializeDisconnect( const MQTTPropBuilder_t * pDisconnectProperties, MQTTSuccessFailReasonCode_t * pReasonCode, - size_t remainingLength, + uint32_t remainingLength, const MQTTFixedBuffer_t * pFixedBuffer ) { MQTTStatus_t result; @@ -73,8 +73,8 @@ MQTTStatus_t MQTT_DeserializeDisconnect( const MQTTPacketInfo_t * pPacket, } MQTTStatus_t MQTT_GetDisconnectPacketSize( const MQTTPropBuilder_t * pDisconnectProperties, - size_t * pRemainingLength, - size_t * pPacketSize, + uint32_t * pRemainingLength, + uint32_t * pPacketSize, uint32_t maxPacketSize, MQTTSuccessFailReasonCode_t * pReasonCode ) { diff --git a/test/cbmc/proofs/MQTT_SerializeDisconnect/MQTT_SerializeDisconnect_harness.c b/test/cbmc/proofs/MQTT_SerializeDisconnect/MQTT_SerializeDisconnect_harness.c index 237043be..63b9284d 100644 --- a/test/cbmc/proofs/MQTT_SerializeDisconnect/MQTT_SerializeDisconnect_harness.c +++ b/test/cbmc/proofs/MQTT_SerializeDisconnect/MQTT_SerializeDisconnect_harness.c @@ -35,8 +35,8 @@ void harness() MQTTPropBuilder_t * pDisconnectProperties; MQTTSuccessFailReasonCode_t * reasonCode = NULL; MQTTStatus_t status; - size_t remainingLength; - size_t packetSize; + uint32_t remainingLength; + uint32_t packetSize; uint32_t maxPacketSize; pDisconnectProperties = allocateMqttPropBuilder( NULL ); diff --git a/test/cbmc/proofs/MQTT_SerializePublish/MQTT_SerializePublish_harness.c b/test/cbmc/proofs/MQTT_SerializePublish/MQTT_SerializePublish_harness.c index ca6c163b..16eb1b9c 100644 --- a/test/cbmc/proofs/MQTT_SerializePublish/MQTT_SerializePublish_harness.c +++ b/test/cbmc/proofs/MQTT_SerializePublish/MQTT_SerializePublish_harness.c @@ -33,8 +33,8 @@ void harness() { MQTTPublishInfo_t * pPublishInfo; uint16_t packetId; - size_t remainingLength; - size_t packetSize; + uint32_t remainingLength; + uint32_t packetSize; const MQTTFixedBuffer_t * pFixedBuffer; MQTTPropBuilder_t * pPublishProperties; MQTTStatus_t status = MQTTSuccess; diff --git a/test/cbmc/proofs/MQTT_SerializePublishHeader/MQTT_SerializePublishHeader_harness.c b/test/cbmc/proofs/MQTT_SerializePublishHeader/MQTT_SerializePublishHeader_harness.c index da4bb26c..6323a20f 100644 --- a/test/cbmc/proofs/MQTT_SerializePublishHeader/MQTT_SerializePublishHeader_harness.c +++ b/test/cbmc/proofs/MQTT_SerializePublishHeader/MQTT_SerializePublishHeader_harness.c @@ -33,8 +33,8 @@ void harness() { MQTTPublishInfo_t * pPublishInfo; uint16_t packetId; - size_t remainingLength; - size_t packetSize; + uint32_t remainingLength; + uint32_t packetSize; MQTTFixedBuffer_t * pFixedBuffer; size_t * pHeaderSize; MQTTPropBuilder_t * pPublishProperties; diff --git a/test/cbmc/proofs/MQTT_SerializeSubscribe/MQTT_SerializeSubscribe_harness.c b/test/cbmc/proofs/MQTT_SerializeSubscribe/MQTT_SerializeSubscribe_harness.c index 1cb26563..9c00e7f5 100644 --- a/test/cbmc/proofs/MQTT_SerializeSubscribe/MQTT_SerializeSubscribe_harness.c +++ b/test/cbmc/proofs/MQTT_SerializeSubscribe/MQTT_SerializeSubscribe_harness.c @@ -33,9 +33,9 @@ void harness() { MQTTSubscribeInfo_t * pSubscriptionList; size_t subscriptionCount; - size_t remainingLength; + uint32_t remainingLength; uint16_t packetId; - size_t packetSize; + uint32_t packetSize; MQTTFixedBuffer_t * pFixedBuffer; MQTTStatus_t status = MQTTSuccess; MQTTPropBuilder_t * pSubscribeProperties; diff --git a/test/cbmc/proofs/MQTT_SerializeUnsubscribe/MQTT_SerializeUnsubscribe_harness.c b/test/cbmc/proofs/MQTT_SerializeUnsubscribe/MQTT_SerializeUnsubscribe_harness.c index e518b7d2..3cf653b5 100644 --- a/test/cbmc/proofs/MQTT_SerializeUnsubscribe/MQTT_SerializeUnsubscribe_harness.c +++ b/test/cbmc/proofs/MQTT_SerializeUnsubscribe/MQTT_SerializeUnsubscribe_harness.c @@ -33,14 +33,14 @@ void harness() { MQTTSubscribeInfo_t * pSubscriptionList; size_t subscriptionCount; - size_t remainingLength; + uint32_t remainingLength; uint16_t packetId; MQTTPropBuilder_t * pUnsubscribeProperties; uint32_t maxPacketSize; /* This variable is not used but is needed for MQTT_GetUnsubscribePacketSize() * to verify the pSubscriptionList. */ - size_t packetSize; + uint32_t packetSize; MQTTFixedBuffer_t * pFixedBuffer; MQTTStatus_t status = MQTTSuccess; diff --git a/test/cbmc/proofs/MQTT_SkipNextProperty/MQTT_SkipNextProperty_harness.c b/test/cbmc/proofs/MQTT_SkipNextProperty/MQTT_SkipNextProperty_harness.c index 841b35a8..f41cbdb8 100644 --- a/test/cbmc/proofs/MQTT_SkipNextProperty/MQTT_SkipNextProperty_harness.c +++ b/test/cbmc/proofs/MQTT_SkipNextProperty/MQTT_SkipNextProperty_harness.c @@ -32,7 +32,7 @@ void harness() { MQTTPropBuilder_t * propBuffer; - uint32_t currentIndex; + size_t currentIndex; propBuffer = allocateMqttPropBuilder( NULL ); __CPROVER_assume( isValidMqttPropBuilder( propBuffer ) ); diff --git a/test/cbmc/proofs/deserializeSubUnsubAckProperties/deserializeSubUnsubAckProperties_harness.c b/test/cbmc/proofs/deserializeSubUnsubAckProperties/deserializeSubUnsubAckProperties_harness.c index a90f952a..9e9145e9 100644 --- a/test/cbmc/proofs/deserializeSubUnsubAckProperties/deserializeSubUnsubAckProperties_harness.c +++ b/test/cbmc/proofs/deserializeSubUnsubAckProperties/deserializeSubUnsubAckProperties_harness.c @@ -50,7 +50,7 @@ void harness() MQTTPropBuilder_t * propBuffer; uint8_t * packetBytes; size_t propertyLength; - size_t remainingLength; + uint32_t remainingLength; size_t minRemainingLength; propBuffer = allocateMqttPropBuilder( NULL ); diff --git a/test/unit-test/core_mqtt_prop_serializer_utest.c b/test/unit-test/core_mqtt_prop_serializer_utest.c index 263309b6..a6a6b53c 100644 --- a/test/unit-test/core_mqtt_prop_serializer_utest.c +++ b/test/unit-test/core_mqtt_prop_serializer_utest.c @@ -40,7 +40,7 @@ void test_MQTTPropAdd_SubscriptionId_AllInputs( void ) { - MQTTPropBuilder_t PropertyBuilder; + MQTTPropBuilder_t PropertyBuilder = { 0 }; uint32_t subscriptionId; uint8_t OptionalMqttPacketType; MQTTStatus_t status; @@ -151,7 +151,7 @@ void test_MQTTPropAdd_SubscriptionId_AllInputs( void ) void test_MQTTPropAdd_UserProp_AllInputs( void ) { - MQTTPropBuilder_t PropertyBuilder; + MQTTPropBuilder_t PropertyBuilder = { 0 }; MQTTUserProperty_t userProperty = { 0 }; uint8_t OptionalMqttPacketType = 0; MQTTStatus_t status; @@ -246,7 +246,7 @@ void test_MQTTPropAdd_UserProp_AllInputs( void ) void test_MQTTPropAdd_SessionExpiry_AllInputs( void ) { - MQTTPropBuilder_t PropertyBuilder; + MQTTPropBuilder_t PropertyBuilder = { 0 }; uint32_t sessionExpiry = 0; uint8_t OptionalMqttPacketType = 0; MQTTStatus_t status; @@ -315,7 +315,7 @@ void test_MQTTPropAdd_SessionExpiry_AllInputs( void ) void test_MQTTPropAdd_ReceiveMax_AllCases( void ) { - MQTTPropBuilder_t PropertyBuilder; + MQTTPropBuilder_t PropertyBuilder = { 0 }; uint16_t receiveMax = 10; uint8_t OptionalMqttPacketType = 0; MQTTStatus_t status; @@ -388,7 +388,7 @@ void test_MQTTPropAdd_ReceiveMax_AllCases( void ) void test_MQTTPropAdd_MaxPacketSize_AllInputs( void ) { - MQTTPropBuilder_t PropertyBuilder; + MQTTPropBuilder_t PropertyBuilder = { 0 }; uint32_t maxPacketSize = 10; uint8_t OptionalMqttPacketType = 0; MQTTStatus_t status; @@ -460,7 +460,7 @@ void test_MQTTPropAdd_MaxPacketSize_AllInputs( void ) void test_MQTTPropAdd_MessageExpiry_AllInputs( void ) { - MQTTPropBuilder_t PropertyBuilder; + MQTTPropBuilder_t PropertyBuilder = { 0 }; uint32_t messageExpiry = 10; uint8_t OptionalMqttPacketType = 0; MQTTStatus_t status; @@ -537,7 +537,7 @@ void test_MQTTPropAdd_MessageExpiry_AllInputs( void ) void test_MQTTPropAdd_WillDelayInterval_AllInputs( void ) { - MQTTPropBuilder_t PropertyBuilder; + MQTTPropBuilder_t PropertyBuilder = { 0 }; uint32_t willDelayInterVal = 10; uint8_t OptionalMqttPacketType = 0; MQTTStatus_t status; @@ -615,7 +615,7 @@ void test_MQTTPropAdd_WillDelayInterval_AllInputs( void ) void test_MQTTPropAdd_TopicAliasMax_AllCases( void ) { - MQTTPropBuilder_t PropertyBuilder; + MQTTPropBuilder_t PropertyBuilder = { 0 }; uint16_t topicAliasMax = 10; uint8_t OptionalMqttPacketType = 0; MQTTStatus_t status; @@ -756,7 +756,7 @@ void test_MQTTPropAdd_TopicAliasMax_AllCases( void ) void test_MQTTPropAdd_TopicAlias_AllCases( void ) { - MQTTPropBuilder_t PropertyBuilder; + MQTTPropBuilder_t PropertyBuilder = { 0 }; uint16_t topicAliasMax = 10; uint8_t OptionalMqttPacketType = MQTT_PACKET_TYPE_PUBLISH; MQTTStatus_t status; @@ -866,7 +866,7 @@ void test_MQTTPropAdd_TopicAlias_AllCases( void ) void test_MQTTPropAdd_RequestRespInfo_AllCases( void ) { - MQTTPropBuilder_t PropertyBuilder; + MQTTPropBuilder_t PropertyBuilder = { 0 }; bool requestRespInfo = false; uint8_t OptionalMqttPacketType = MQTT_PACKET_TYPE_CONNECT; MQTTStatus_t status; @@ -964,7 +964,7 @@ void test_MQTTPropAdd_RequestRespInfo_AllCases( void ) void test_MQTTPropAdd_RequestProbInfo_AllCases( void ) { - MQTTPropBuilder_t PropertyBuilder; + MQTTPropBuilder_t PropertyBuilder = { 0 }; bool requestRespInfo = false; uint8_t OptionalMqttPacketType = MQTT_PACKET_TYPE_CONNECT; MQTTStatus_t status; @@ -1063,7 +1063,7 @@ void test_MQTTPropAdd_RequestProbInfo_AllCases( void ) void test_MQTTPropAdd_PayloadFormat_AllCases( void ) { - MQTTPropBuilder_t PropertyBuilder; + MQTTPropBuilder_t PropertyBuilder = { 0 }; bool requestRespInfo = false; uint8_t OptionalMqttPacketType = MQTT_PACKET_TYPE_CONNECT; MQTTStatus_t status; @@ -1162,7 +1162,7 @@ void test_MQTTPropAdd_PayloadFormat_AllCases( void ) void test_MQTTPropAdd_AuthMethod_AllCases( void ) { - MQTTPropBuilder_t PropertyBuilder; + MQTTPropBuilder_t PropertyBuilder = { 0 }; uint8_t OptionalMqttPacketType = MQTT_PACKET_TYPE_CONNECT; uint8_t buffer[ 100 ]; MQTTStatus_t status; @@ -1247,7 +1247,7 @@ void test_MQTTPropAdd_AuthMethod_AllCases( void ) void test_MQTTPropAdd_AuthData_AllCases( void ) { - MQTTPropBuilder_t PropertyBuilder; + MQTTPropBuilder_t PropertyBuilder = { 0 }; uint8_t OptionalMqttPacketType = MQTT_PACKET_TYPE_CONNECT; uint8_t buffer[ 100 ]; MQTTStatus_t status; @@ -1333,7 +1333,7 @@ void test_MQTTPropAdd_AuthData_AllCases( void ) void test_MQTTPropAdd_ReasonString_AllCases( void ) { - MQTTPropBuilder_t PropertyBuilder; + MQTTPropBuilder_t PropertyBuilder = { 0 }; uint8_t OptionalMqttPacketType = MQTT_PACKET_TYPE_CONNECT; uint8_t buffer[ 100 ]; MQTTStatus_t status; @@ -1426,7 +1426,7 @@ void test_MQTTPropAdd_ReasonString_AllCases( void ) void test_MQTTPropAdd_ContentType_AllCases( void ) { - MQTTPropBuilder_t PropertyBuilder; + MQTTPropBuilder_t PropertyBuilder = { 0 }; uint8_t OptionalMqttPacketType = MQTT_PACKET_TYPE_CONNECT; uint8_t buffer[ 100 ]; MQTTStatus_t status; @@ -1503,7 +1503,7 @@ void test_MQTTPropAdd_ContentType_AllCases( void ) void test_MQTTPropAdd_CorrelationData_AllCases( void ) { - MQTTPropBuilder_t PropertyBuilder; + MQTTPropBuilder_t PropertyBuilder = { 0 }; uint8_t OptionalMqttPacketType = MQTT_PACKET_TYPE_CONNECT; uint8_t buffer[ 100 ]; MQTTStatus_t status; @@ -1580,7 +1580,7 @@ void test_MQTTPropAdd_CorrelationData_AllCases( void ) void test_MQTTPropAdd_ResponseTopic_AllCases( void ) { - MQTTPropBuilder_t PropertyBuilder; + MQTTPropBuilder_t PropertyBuilder = { 0 }; uint8_t OptionalMqttPacketType = MQTT_PACKET_TYPE_CONNECT; uint8_t buffer[ 100 ] = { 0 }; MQTTStatus_t status; diff --git a/test/unit-test/core_mqtt_serializer_utest.c b/test/unit-test/core_mqtt_serializer_utest.c index f91bd1b0..f14790f6 100644 --- a/test/unit-test/core_mqtt_serializer_utest.c +++ b/test/unit-test/core_mqtt_serializer_utest.c @@ -93,7 +93,6 @@ struct NetworkContext #define TEST_TOPIC_ALIAS ( 2U ) #define TEST_MSG_EXPIRY ( 100U ) - #define MQTT_TEST_UTF8_STRING ( "test" ) #define MQTT_TEST_UTF8_STRING_LENGTH ( sizeof( MQTT_TEST_UTF8_STRING ) - 1 ) #define MQTT_TEST_UINT8 ( 1U ) @@ -109,7 +108,7 @@ struct NetworkContext #define MQTT_CONNECT_FLAG_PASSWORD ( 6 ) /**< @brief Password present. */ #define MQTT_CONNECT_FLAG_USERNAME ( 7 ) /**< @brief User name present. */ -/*Default connect properties. */ +/* Default connect properties. */ #define DEFAULT_RECEIVE_MAX ( 65535U ) #define DEFAULT_REQUEST_PROBLEM ( 1 ) @@ -180,7 +179,6 @@ struct NetworkContext #define UINT32_BYTE0( x ) ( ( uint8_t ) ( ( x ) & 0x000000FFU ) ) - #define MQTT_MAX_PACKET_SIZE ( 268435460UL ) /* Variables common to testcases */ @@ -302,7 +300,6 @@ static int32_t mockReceiveSucceedThenFail( NetworkContext_t * pNetworkContext, /* ========================================================================== */ - /** * @brief Initialize pPublishInfo using test-defined macros. * @@ -331,7 +328,7 @@ static size_t encodeVariableLengthUT( uint8_t * pDestination, { uint8_t lengthByte; uint8_t * pLengthEnd = NULL; - size_t remainingLength = length; + uint32_t remainingLength = length; TEST_ASSERT_NOT_NULL( pDestination ); @@ -437,7 +434,6 @@ static size_t encodeStringSize( uint8_t * pDestination, return ( size_t ) ( pBuffer - pDestination ); } - /** * @brief Pad beginning and end of buffer with non-zero bytes to be used in * checking for under/overflow after serialization. @@ -479,7 +475,6 @@ static void checkBufferOverflow( uint8_t * pBuffer, BUFFER_PADDING_LENGTH ); } - static uint8_t * initializeDeserialize( MQTTPacketInfo_t * packetInfo, uint8_t * pIndex ) { @@ -509,7 +504,6 @@ static uint8_t * serializeuint_32( uint8_t * pIndex, return pIndexLocal; } - static uint8_t * serializeuint_16( uint8_t * pIndex, uint8_t propertyId ) { @@ -559,7 +553,6 @@ static uint8_t * serializeutf_8pair( uint8_t * pIndex ) return pIndexLocal; } - void test_MQTTV5_DeserializeConnackOnlyStatus( void ) { uint8_t buffer[ 50 ]; @@ -604,7 +597,6 @@ void test_MQTTV5_DeserializeConnackOnlyStatus( void ) status = MQTT_DeserializeConnAck( &packetInfo, &sessionPresent, &propBuffer, &properties ); TEST_ASSERT_EQUAL( MQTTBadParameter, status ); - /* Incomplete connack received. */ sessionPresent = false; packetInfo.pRemainingData = pIndex; @@ -632,12 +624,12 @@ void test_MQTTV5_DeserializeConnackOnlyStatus( void ) /* 5 + 1 + 2 = 8 */ size_t propertyLength = encodeVariableLengthUT( pIndex, 5 ); packetInfo.remainingLength = propertyLength + 7; - /*Not a valid reason code*/ + /* Not a valid reason code*/ buffer[ 0 ] = 0x00; buffer[ 1 ] = 0x03; status = MQTT_DeserializeConnAck( &packetInfo, &sessionPresent, &propBuffer, &properties ); TEST_ASSERT_EQUAL( MQTTBadResponse, status ); - /*All the valid response code*/ + /* All the valid response code*/ buffer[ 1 ] = 0x80; buffer[ 2 ] = 0; properties.maxPacketSize = 100; @@ -745,26 +737,26 @@ void test_MQTTV5_DeserializeConnackOnlyStatus( void ) status = MQTT_DeserializeConnAck( &packetInfo, &sessionPresent, &propBuffer, &properties ); TEST_ASSERT_EQUAL( MQTTServerRefused, status ); - /*Exceeds the max packet size set by the client*/ + /* Exceeds the max packet size set by the client*/ properties.maxPacketSize = 2; buffer[ 1 ] = 0x00; status = MQTT_DeserializeConnAck( &packetInfo, &sessionPresent, &propBuffer, &properties ); TEST_ASSERT_EQUAL( MQTTBadResponse, status ); - /*Validate the remaining length*/ + /* Validate the remaining length*/ properties.maxPacketSize = MQTT_MAX_PACKET_SIZE; packetInfo.remainingLength = 7; status = MQTT_DeserializeConnAck( &packetInfo, &sessionPresent, &propBuffer, &properties ); TEST_ASSERT_EQUAL( MQTTBadResponse, status ); - /*Invalid property length*/ + /* Invalid property length*/ packetInfo.remainingLength = 20; pIndex = &buffer[ 2 ]; propertyLength = encodeVariableLengthUT( pIndex, 20971556356235 ); status = MQTT_DeserializeConnAck( &packetInfo, &sessionPresent, &propBuffer, &properties ); TEST_ASSERT_EQUAL_INT( MQTTBadResponse, status ); - /*Invalid property length*/ + /* Invalid property length*/ pIndex = &buffer[ 2 ]; *pIndex = 0x81; pIndex++; @@ -794,11 +786,11 @@ void test_MQTTV5_DeserializeConnackOnlyuint_32( void ) TEST_ASSERT_EQUAL_INT( MQTT_TEST_UINT32, properties.sessionExpiry ); TEST_ASSERT_EQUAL_INT( MQTT_TEST_UINT32, properties.serverMaxPacketSize ); - /*Test with NULL propBuffer. */ + /* Test with NULL propBuffer. */ status = MQTT_DeserializeConnAck( &packetInfo, &session, NULL, &properties ); TEST_ASSERT_EQUAL_INT( MQTTSuccess, status ); - /*Protocol error to include the same property twice*/ + /* Protocol error to include the same property twice*/ packetInfo.remainingLength = 13; pIndexLocal = &buffer[ 2 ]; propertyLength = encodeVariableLengthUT( pIndexLocal, 10 ); @@ -808,7 +800,7 @@ void test_MQTTV5_DeserializeConnackOnlyuint_32( void ) status = MQTT_DeserializeConnAck( &packetInfo, &session, &propBuffer, &properties ); TEST_ASSERT_EQUAL_INT( MQTTBadResponse, status ); - /*Invalid property length*/ + /* Invalid property length*/ packetInfo.remainingLength = 7; pIndexLocal = &buffer[ 2 ]; propertyLength = encodeVariableLengthUT( pIndexLocal, 4 ); @@ -819,7 +811,7 @@ void test_MQTTV5_DeserializeConnackOnlyuint_32( void ) status = MQTT_DeserializeConnAck( &packetInfo, &session, &propBuffer, &properties ); TEST_ASSERT_EQUAL_INT( MQTTBadResponse, status ); - /*Invalid id*/ + /* Invalid id*/ packetInfo.remainingLength = 8; pIndexLocal = &buffer[ 2 ]; propertyLength = encodeVariableLengthUT( pIndexLocal, 5 ); @@ -869,7 +861,7 @@ void test_MQTTV5_DeserializeConnackOnlyuint_16( void ) TEST_ASSERT_EQUAL_INT( MQTT_TEST_UINT16, properties.serverTopicAliasMax ); TEST_ASSERT_EQUAL_INT( MQTT_TEST_UINT16, properties.serverKeepAlive ); - /*Receive Max cannot have a value 0*/ + /* Receive Max cannot have a value 0*/ pIndexLocal = &buffer[ 2 ]; propertyLength = encodeVariableLengthUT( pIndexLocal, 3 ); packetInfo.remainingLength = propertyLength + 5; @@ -882,7 +874,7 @@ void test_MQTTV5_DeserializeConnackOnlyuint_16( void ) status = MQTT_DeserializeConnAck( &packetInfo, &session, &propBuffer, &properties ); TEST_ASSERT_EQUAL_INT( MQTTBadResponse, status ); - /*Protocol error to include the same property twice*/ + /* Protocol error to include the same property twice*/ pIndexLocal = &buffer[ 2 ]; propertyLength = encodeVariableLengthUT( pIndexLocal, 6 ); packetInfo.remainingLength = propertyLength + 8; @@ -892,7 +884,7 @@ void test_MQTTV5_DeserializeConnackOnlyuint_16( void ) status = MQTT_DeserializeConnAck( &packetInfo, &session, &propBuffer, &properties ); TEST_ASSERT_EQUAL_INT( MQTTBadResponse, status ); - /*Invalid property length*/ + /* Invalid property length*/ packetInfo.remainingLength = 5; pIndexLocal = &buffer[ 2 ]; propertyLength = encodeVariableLengthUT( pIndexLocal, 2 ); @@ -932,7 +924,7 @@ void test_MQTTV5_DeserializeConnackOnlyuint_8( void ) TEST_ASSERT_EQUAL_INT( MQTT_TEST_UINT8, properties.isSharedAvailable ); TEST_ASSERT_EQUAL_INT( MQTT_TEST_UINT8, properties.isSubscriptionIdAvailable ); - /*Protocol error to have a value other than 0 or 1*/ + /* Protocol error to have a value other than 0 or 1*/ packetInfo.remainingLength = 5; pIndexLocal = &buffer[ 2 ]; propertyLength = encodeVariableLengthUT( pIndexLocal, 2 ); @@ -944,7 +936,7 @@ void test_MQTTV5_DeserializeConnackOnlyuint_8( void ) status = MQTT_DeserializeConnAck( &packetInfo, &session, &propBuffer, &properties ); TEST_ASSERT_EQUAL_INT( MQTTBadResponse, status ); - /*Protocol error to include the same property twice*/ + /* Protocol error to include the same property twice*/ pIndexLocal = &buffer[ 2 ]; propertyLength = encodeVariableLengthUT( pIndexLocal, 4 ); packetInfo.remainingLength = propertyLength + 6; @@ -954,7 +946,7 @@ void test_MQTTV5_DeserializeConnackOnlyuint_8( void ) status = MQTT_DeserializeConnAck( &packetInfo, &session, &propBuffer, &properties ); TEST_ASSERT_EQUAL_INT( MQTTBadResponse, status ); - /*Invalid property length*/ + /* Invalid property length*/ packetInfo.remainingLength = 4; pIndexLocal = &buffer[ 2 ]; propertyLength = encodeVariableLengthUT( pIndexLocal, 1 ); @@ -1006,7 +998,6 @@ void test_MQTTV5_DeserializeConnackOnlyuint_8( void ) } } - void test_MQTTV5_DeserializeConnackOnlyutf_8( void ) { uint8_t buffer[ 200 ] = { 0 }; @@ -1032,7 +1023,7 @@ void test_MQTTV5_DeserializeConnackOnlyutf_8( void ) status = MQTT_DeserializeConnAck( &packetInfo, &session, &propBuffer, &properties ); TEST_ASSERT_EQUAL_INT( MQTTSuccess, status ); - /*Protocol error to include the same property twice*/ + /* Protocol error to include the same property twice*/ packetInfo.remainingLength = 17; pIndexLocal = &buffer[ 2 ]; propertyLength = encodeVariableLengthUT( pIndexLocal, 14 ); @@ -1042,7 +1033,7 @@ void test_MQTTV5_DeserializeConnackOnlyutf_8( void ) status = MQTT_DeserializeConnAck( &packetInfo, &session, &propBuffer, &properties ); TEST_ASSERT_EQUAL_INT( MQTTBadResponse, status ); - /*Invalid property length*/ + /* Invalid property length*/ packetInfo.remainingLength = 7; pIndexLocal = &buffer[ 2 ]; propertyLength = encodeVariableLengthUT( pIndexLocal, 4 ); @@ -1051,7 +1042,7 @@ void test_MQTTV5_DeserializeConnackOnlyutf_8( void ) status = MQTT_DeserializeConnAck( &packetInfo, &session, &propBuffer, &properties ); TEST_ASSERT_EQUAL_INT( MQTTBadResponse, status ); - /*Invalid property length*/ + /* Invalid property length*/ pIndexLocal = &buffer[ 2 ]; propertyLength = encodeVariableLengthUT( pIndexLocal, 2 ); packetInfo.remainingLength = propertyLength + 4; @@ -1060,7 +1051,7 @@ void test_MQTTV5_DeserializeConnackOnlyutf_8( void ) status = MQTT_DeserializeConnAck( &packetInfo, &session, &propBuffer, &properties ); TEST_ASSERT_EQUAL_INT( MQTTBadResponse, status ); - /*Protocol error to include response information if is is set to false by client*/ + /* Protocol error to include response information if is is set to false by client*/ properties.requestResponseInfo = 0; packetInfo.remainingLength = 10; pIndexLocal = &buffer[ 2 ]; @@ -1086,7 +1077,6 @@ void test_MQTTV5_DeserializeConnackOnlyutf_8( void ) TEST_ASSERT_EQUAL_INT( MQTTSuccess, status ); } - void test_MQTTV5_DeserializeConnackOnlyUserProperty( void ) { uint8_t buffer[ 70000 ] = { 0 }; @@ -1108,7 +1098,7 @@ void test_MQTTV5_DeserializeConnackOnlyUserProperty( void ) status = MQTT_DeserializeConnAck( &packetInfo, &sessionPresent, &propBuffer, &properties ); TEST_ASSERT_EQUAL_INT( MQTTSuccess, status ); - /*Invalid property length*/ + /* Invalid property length*/ packetInfo.remainingLength = 5; pIndexLocal = &buffer[ 2 ]; propertyLength = encodeVariableLengthUT( pIndexLocal, 2 ); @@ -1117,7 +1107,7 @@ void test_MQTTV5_DeserializeConnackOnlyUserProperty( void ) status = MQTT_DeserializeConnAck( &packetInfo, &sessionPresent, &propBuffer, &properties ); TEST_ASSERT_EQUAL_INT( MQTTBadResponse, status ); - /*Invalid property length*/ + /* Invalid property length*/ packetInfo.remainingLength = 6; pIndexLocal = &buffer[ 2 ]; propertyLength = encodeVariableLengthUT( pIndexLocal, 3 ); @@ -1126,7 +1116,7 @@ void test_MQTTV5_DeserializeConnackOnlyUserProperty( void ) status = MQTT_DeserializeConnAck( &packetInfo, &sessionPresent, &propBuffer, &properties ); TEST_ASSERT_EQUAL_INT( MQTTBadResponse, status ); - /*Invalid property length*/ + /* Invalid property length*/ pIndexLocal = &buffer[ 2 ]; propertyLength = encodeVariableLengthUT( pIndexLocal, 8 ); packetInfo.remainingLength = propertyLength + 10; @@ -1135,7 +1125,7 @@ void test_MQTTV5_DeserializeConnackOnlyUserProperty( void ) status = MQTT_DeserializeConnAck( &packetInfo, &sessionPresent, &propBuffer, &properties ); TEST_ASSERT_EQUAL_INT( MQTTBadResponse, status ); - /*Invalid property length*/ + /* Invalid property length*/ packetInfo.remainingLength = 15; pIndexLocal = &buffer[ 2 ]; propertyLength = encodeVariableLengthUT( pIndexLocal, 12 ); @@ -1144,7 +1134,7 @@ void test_MQTTV5_DeserializeConnackOnlyUserProperty( void ) status = MQTT_DeserializeConnAck( &packetInfo, &sessionPresent, &propBuffer, &properties ); TEST_ASSERT_EQUAL_INT( MQTTBadResponse, status ); - /*Discard user property*/ + /* Discard user property*/ packetInfo.remainingLength = 65018; pIndexLocal = &buffer[ 2 ]; propertyLength = encodeVariableLengthUT( pIndexLocal, 65013 ); @@ -1173,8 +1163,6 @@ void test_MQTTV5_DeserializeConnackOnlyUserProperty( void ) TEST_ASSERT_EQUAL_INT( MQTTBadResponse, status ); } - - void test_MQTTV5_GetConnectPacketSize( void ) { uint32_t remainingLength = 0; @@ -1225,6 +1213,29 @@ void test_MQTTV5_GetConnectPacketSize( void ) status = MQTT_GetConnectPacketSize( &connectInfo, &publishInfo, NULL, NULL, &remainingLength, &packetSize ); TEST_ASSERT_EQUAL( MQTTBadParameter, status ); + memset( &connectInfo, 0x0, sizeof( connectInfo ) ); + connectInfo.cleanSession = true; + connectInfo.pClientIdentifier = "TEST"; + connectInfo.clientIdentifierLength = 65536; + status = MQTT_GetConnectPacketSize( &connectInfo, NULL, NULL, NULL, &remainingLength, &packetSize ); + TEST_ASSERT_EQUAL_INT( MQTTBadParameter, status ); + + memset( &connectInfo, 0x0, sizeof( connectInfo ) ); + connectInfo.cleanSession = true; + connectInfo.pClientIdentifier = "TEST"; + connectInfo.clientIdentifierLength = 4; + connectInfo.userNameLength = 65536; + status = MQTT_GetConnectPacketSize( &connectInfo, NULL, NULL, NULL, &remainingLength, &packetSize ); + TEST_ASSERT_EQUAL_INT( MQTTBadParameter, status ); + + memset( &connectInfo, 0x0, sizeof( connectInfo ) ); + connectInfo.cleanSession = true; + connectInfo.pClientIdentifier = "TEST"; + connectInfo.clientIdentifierLength = 4; + connectInfo.passwordLength = 65536; + status = MQTT_GetConnectPacketSize( &connectInfo, NULL, NULL, NULL, &remainingLength, &packetSize ); + TEST_ASSERT_EQUAL_INT( MQTTBadParameter, status ); + /* Verify good case */ memset( &connectInfo, 0x0, sizeof( connectInfo ) ); connectInfo.cleanSession = true; @@ -1245,6 +1256,13 @@ void test_MQTTV5_GetConnectPacketSize( void ) status = MQTT_GetConnectPacketSize( &connectInfo, &publishInfo, &propBuffer, &propBuffer, &remainingLength, &packetSize ); TEST_ASSERT_EQUAL( MQTTBadParameter, status ); + publishInfo.pTopicName = "test"; + publishInfo.topicNameLength = 65536; + publishInfo.pPayload = "testload"; + publishInfo.payloadLength = 8; + status = MQTT_GetConnectPacketSize( &connectInfo, &publishInfo, NULL, NULL, &remainingLength, &packetSize ); + TEST_ASSERT_EQUAL_INT( MQTTBadParameter, status ); + /* With will. These parameters will cause the packet to be * 4 + 2 + 8 + 2 = 16 bytes larger. */ publishInfo.pTopicName = "test"; @@ -1279,6 +1297,22 @@ void test_MQTTV5_GetConnectPacketSize( void ) propBuffer.currentIndex = MQTT_MAX_REMAINING_LENGTH + 1; status = MQTT_GetConnectPacketSize( &connectInfo, NULL, &propBuffer, NULL, &remainingLength, &packetSize ); TEST_ASSERT_EQUAL( MQTTBadParameter, status ); + + propBuffer.pBuffer = buf; + propBuffer.currentIndex = MQTT_MAX_REMAINING_LENGTH + 1; + status = MQTT_GetConnectPacketSize( &connectInfo, NULL, NULL, &propBuffer, &remainingLength, &packetSize ); + TEST_ASSERT_EQUAL( MQTTBadParameter, status ); + + /* With username and password. This will add 4 + 2 + 4 + 2 = 12 bytes. */ + connectInfo.cleanSession = true; + connectInfo.pUserName = "USER"; + connectInfo.userNameLength = 1; + connectInfo.pPassword = "PASS"; + connectInfo.passwordLength = 1; + propBuffer.pBuffer = buf; + propBuffer.currentIndex = MQTT_MAX_REMAINING_LENGTH - 1; + status = MQTT_GetConnectPacketSize( &connectInfo, NULL, &propBuffer, NULL, &remainingLength, &packetSize ); + TEST_ASSERT_EQUAL( MQTTBadParameter, status ); } /** @@ -1286,7 +1320,7 @@ void test_MQTTV5_GetConnectPacketSize( void ) */ void test_MQTT_SerializeConnect( void ) { - MQTTConnectInfo_t connectInfo; + MQTTConnectInfo_t connectInfo = { 0 }; MQTTPublishInfo_t willInfo = { 0 }; uint32_t remainingLength = 0; uint8_t buffer[ 70 + 2 * BUFFER_PADDING_LENGTH ]; @@ -1305,6 +1339,12 @@ void test_MQTT_SerializeConnect( void ) status = MQTT_SerializeConnect( &connectInfo, NULL, NULL, NULL, 120, &fixedBuffer ); TEST_ASSERT_EQUAL_INT( MQTTNoMemory, status ); + memset( &connectInfo, 0x0, sizeof( connectInfo ) ); + connectInfo.pClientIdentifier = "TEST"; + connectInfo.clientIdentifierLength = 4; + status = MQTT_SerializeConnect( &connectInfo, NULL, NULL, NULL, 120, &fixedBuffer ); + TEST_ASSERT_EQUAL_INT( MQTTNoMemory, status ); + /* Create a good connection info. */ memset( &connectInfo, 0x0, sizeof( connectInfo ) ); connectInfo.pClientIdentifier = "TEST"; @@ -1315,6 +1355,39 @@ void test_MQTT_SerializeConnect( void ) status = MQTT_SerializeConnect( &connectInfo, NULL, NULL, NULL, remainingLength, &fixedBuffer ); TEST_ASSERT_EQUAL_INT( MQTTBadParameter, status ); + memset( &connectInfo, 0x0, sizeof( connectInfo ) ); + fixedBuffer.pBuffer = &buffer[ BUFFER_PADDING_LENGTH ]; + connectInfo.pClientIdentifier = "TEST"; + connectInfo.clientIdentifierLength = 65536; + status = MQTT_SerializeConnect( &connectInfo, NULL, NULL, NULL, remainingLength, &fixedBuffer ); + TEST_ASSERT_EQUAL( MQTTBadParameter, status ); + + memset( &connectInfo, 0x0, sizeof( connectInfo ) ); + connectInfo.pClientIdentifier = "TEST"; + connectInfo.clientIdentifierLength = 4; + connectInfo.userNameLength = 65536; + status = MQTT_SerializeConnect( &connectInfo, NULL, NULL, NULL, remainingLength, &fixedBuffer ); + TEST_ASSERT_EQUAL( MQTTBadParameter, status ); + + memset( &connectInfo, 0x0, sizeof( connectInfo ) ); + connectInfo.pClientIdentifier = "TEST"; + connectInfo.clientIdentifierLength = 4; + connectInfo.passwordLength = 65536; + status = MQTT_SerializeConnect( &connectInfo, NULL, NULL, NULL, remainingLength, &fixedBuffer ); + TEST_ASSERT_EQUAL( MQTTBadParameter, status ); + + memset( &willInfo, 0x00, sizeof( MQTTPublishInfo_t ) ); + memset( &connectInfo, 0x0, sizeof( connectInfo ) ); + connectInfo.pClientIdentifier = "TEST"; + connectInfo.clientIdentifierLength = 4; + willInfo.pTopicName = "TOPIC"; + willInfo.topicNameLength = 65536; + status = MQTT_SerializeConnect( &connectInfo, &willInfo, NULL, NULL, remainingLength, &fixedBuffer ); + TEST_ASSERT_EQUAL( MQTTBadParameter, status ); + + memset( &connectInfo, 0x0, sizeof( connectInfo ) ); + connectInfo.pClientIdentifier = "TEST"; + connectInfo.clientIdentifierLength = 4; /* Good case succeeds. */ /* Set the fixedBuffer properly for the rest of the succeeding test. */ fixedBuffer.pBuffer = &buffer[ BUFFER_PADDING_LENGTH ]; @@ -1444,7 +1517,7 @@ void test_MQTT_SerializeConnect( void ) TEST_ASSERT_EQUAL( MQTTSuccess, status ); checkBufferOverflow( buffer, sizeof( buffer ) ); - /*Test with null buffer*/ + /* Test with null buffer*/ propBuffer.pBuffer = NULL; status = MQTT_SerializeConnect( &connectInfo, &willInfo, NULL, &propBuffer, remainingLength, &fixedBuffer ); TEST_ASSERT_EQUAL( MQTTSuccess, status ); @@ -1455,8 +1528,8 @@ void test_MQTT_SerializeConnect( void ) void test_RemaininglengthLimit( void ) { /* Test will property length more than the max value allowed. */ - size_t remainingLength = 0; - size_t packetSize = 0; + uint32_t remainingLength = 0; + uint32_t packetSize = 0; uint32_t maxPacketSize = 100; MQTTStatus_t status = MQTTSuccess; @@ -1480,22 +1553,33 @@ void test_MQTTV5_ValidatePublishParams() uint8_t retain = 0U; uint32_t maxPacketSize = 0U; - /*Publish info cannot be null*/ + /* Publish info cannot be null*/ status = MQTT_ValidatePublishParams( NULL, retain, maxQos, topicAlias, maxPacketSize ); TEST_ASSERT_EQUAL( MQTTBadParameter, status ); - /*Retain is not allowed. */ + /* Retain is not allowed. */ publishInfo.retain = true; status = MQTT_ValidatePublishParams( &publishInfo, retain, maxQos, topicAlias, maxPacketSize ); TEST_ASSERT_EQUAL( MQTTBadParameter, status ); - /*Qos invalid*/ + /* Qos invalid*/ publishInfo.retain = false; publishInfo.qos = 1; status = MQTT_ValidatePublishParams( &publishInfo, retain, maxQos, topicAlias, maxPacketSize ); TEST_ASSERT_EQUAL( MQTTBadParameter, status ); - /*Valid parameters should return success*/ + /* Valid parameters except topic name length. */ + publishInfo.qos = 1; + maxQos = 1; + publishInfo.retain = true; + retain = 1; + publishInfo.pTopicName = "abc"; + publishInfo.topicNameLength = 65536; + maxPacketSize = 10; + status = MQTT_ValidatePublishParams( &publishInfo, retain, maxQos, topicAlias, maxPacketSize ); + TEST_ASSERT_EQUAL( MQTTBadParameter, status ); + + /* Valid parameters should return success*/ publishInfo.qos = 1; maxQos = 1; publishInfo.retain = true; @@ -1511,13 +1595,13 @@ void test_MQTTV5_ValidatePublishParams() status = MQTT_ValidatePublishParams( &publishInfo, retain, maxQos, topicAlias, maxPacketSize ); TEST_ASSERT_EQUAL( MQTTSuccess, status ); - /*Invalid topic name and topic name length*/ + /* Invalid topic name and topic name length*/ publishInfo.pTopicName = NULL; publishInfo.topicNameLength = 2; status = MQTT_ValidatePublishParams( &publishInfo, retain, maxQos, topicAlias, maxPacketSize ); TEST_ASSERT_EQUAL( MQTTBadParameter, status ); - /*Invalid maxPacket size*/ + /* Invalid maxPacket size*/ publishInfo.pTopicName = "abc"; publishInfo.topicNameLength = 3; maxPacketSize = 0; @@ -1542,12 +1626,12 @@ void test_MQTTV5_ValidatePublishParams() void test_MQTTV5_GetPublishPacketSize() { - size_t remainingLength = 0U; - size_t packetSize = 0U; + uint32_t remainingLength = 0U; + uint32_t packetSize = 0U; uint32_t maxPacketSize = 0U; setupPublishInfo( &publishInfo ); - /*Test with invalid paramters*/ + /* Test with invalid paramters*/ status = MQTT_GetPublishPacketSize( NULL, NULL, &remainingLength, &packetSize, maxPacketSize ); TEST_ASSERT_EQUAL( MQTTBadParameter, status ); @@ -1560,21 +1644,21 @@ void test_MQTTV5_GetPublishPacketSize() status = MQTT_GetPublishPacketSize( &publishInfo, NULL, &remainingLength, &packetSize, maxPacketSize ); TEST_ASSERT_EQUAL( MQTTBadParameter, status ); - /*Topic name invalid*/ + /* Topic name invalid*/ publishInfo.pTopicName = NULL; status = MQTT_GetPublishPacketSize( &publishInfo, NULL, &remainingLength, &packetSize, maxPacketSize ); TEST_ASSERT_EQUAL( MQTTBadParameter, status ); publishInfo.pTopicName = TEST_TOPIC_NAME; - /*Topic alias is not allowed and topic name is not provided.*/ + /* Topic alias is not allowed and topic name is not provided. */ publishInfo.topicNameLength = 0; status = MQTT_GetPublishPacketSize( &publishInfo, NULL, &remainingLength, &packetSize, maxPacketSize ); TEST_ASSERT_EQUAL( MQTTBadParameter, status ); maxPacketSize = 100; publishInfo.topicNameLength = TEST_TOPIC_NAME_LENGTH; - /*Packet size too large*/ + /* Packet size too large*/ publishInfo.payloadLength = MQTT_MAX_REMAINING_LENGTH; status = MQTT_GetPublishPacketSize( &publishInfo, NULL, &remainingLength, &packetSize, maxPacketSize ); TEST_ASSERT_EQUAL( MQTTBadParameter, status ); @@ -1596,7 +1680,7 @@ void test_MQTTV5_GetPublishPacketSize() publishInfo.retain = true; - /*Valid properties*/ + /* Valid properties*/ MQTTPropBuilder_t propBuffer = { 0 }; uint8_t buf[ 100 ]; propBuffer.pBuffer = buf; @@ -1617,7 +1701,7 @@ void test_MQTTV5_GetPublishPacketSize() TEST_ASSERT_EQUAL( MQTTSuccess, status ); propBuffer.pBuffer = buf; - /*Packet size is more than the server allowed max packet size*/ + /* Packet size is more than the server allowed max packet size*/ maxPacketSize = 4; status = MQTT_GetPublishPacketSize( &publishInfo, NULL, &remainingLength, &packetSize, maxPacketSize ); TEST_ASSERT_EQUAL( MQTTBadParameter, status ); @@ -1629,10 +1713,10 @@ void test_MQTTV5_GetPublishPacketSize() void test_MQTT_SerializePublish( void ) { MQTTPublishInfo_t publishInfo; - size_t remainingLength = 98; + uint32_t remainingLength = 98; uint8_t buffer[ 200 + 2 * BUFFER_PADDING_LENGTH ]; size_t bufferSize = sizeof( buffer ) - 2 * BUFFER_PADDING_LENGTH; - size_t packetSize = bufferSize; + uint32_t packetSize = bufferSize; MQTTStatus_t status = MQTTSuccess; MQTTFixedBuffer_t fixedBuffer = { .pBuffer = &buffer[ BUFFER_PADDING_LENGTH ], .size = bufferSize }; uint8_t expectedPacket[ 200 ]; @@ -1838,11 +1922,14 @@ void test_MQTTV5_DeserializeAck_puback( void ) status = MQTT_DeserializeAck( &mqttPacketInfo, NULL, &ackInfo, &propBuffer, &properties ); TEST_ASSERT_EQUAL_INT( MQTTBadParameter, status ); - /*Remaining data cannot be NULL.*/ + status = MQTT_DeserializeAck( &mqttPacketInfo, &packetIdentifier, &ackInfo, &propBuffer, NULL ); + TEST_ASSERT_EQUAL_INT( MQTTBadParameter, status ); + + /* Remaining data cannot be NULL. */ status = MQTT_DeserializeAck( &mqttPacketInfo, &packetIdentifier, &ackInfo, &propBuffer, &properties ); TEST_ASSERT_EQUAL_INT( MQTTBadParameter, status ); - /*Max packet size cannot be 0*/ + /* Max packet size cannot be 0*/ mqttPacketInfo.pRemainingData = buffer; status = MQTT_DeserializeAck( &mqttPacketInfo, &packetIdentifier, &ackInfo, &propBuffer, &properties ); TEST_ASSERT_EQUAL_INT( MQTTBadParameter, status ); @@ -1860,18 +1947,25 @@ void test_MQTTV5_DeserializeAck_puback( void ) status = MQTT_DeserializeAck( &mqttPacketInfo, &packetIdentifier, &ackInfo, &propBuffer, &properties ); TEST_ASSERT_EQUAL_INT( MQTTBadResponse, status ); - - /*Remaining length connot be less than 2*/ + /* Remaining length connot be less than 2*/ mqttPacketInfo.remainingLength = 1; status = MQTT_DeserializeAck( &mqttPacketInfo, &packetIdentifier, &ackInfo, &propBuffer, &properties ); TEST_ASSERT_EQUAL_INT( MQTTBadResponse, status ); - /*Packet size greater than allowed.*/ + /* Packet size greater than allowed. */ mqttPacketInfo.remainingLength = 1000U; status = MQTT_DeserializeAck( &mqttPacketInfo, &packetIdentifier, &ackInfo, &propBuffer, &properties ); TEST_ASSERT_EQUAL_INT( MQTTBadResponse, status ); + /* Should fail to process CONNACK. */ + mqttPacketInfo.type = MQTT_PACKET_TYPE_CONNACK; + mqttPacketInfo.remainingLength = 2; + buffer[ 1 ] = 1; + status = MQTT_DeserializeAck( &mqttPacketInfo, &packetIdentifier, &ackInfo, &propBuffer, &properties ); + TEST_ASSERT_EQUAL_INT( MQTTBadParameter, status ); + /* Process a valid PUBACK. */ + mqttPacketInfo.type = MQTT_PACKET_TYPE_PUBACK; mqttPacketInfo.remainingLength = 2; buffer[ 1 ] = 1; status = MQTT_DeserializeAck( &mqttPacketInfo, &packetIdentifier, &ackInfo, &propBuffer, &properties ); @@ -1884,18 +1978,18 @@ void test_MQTTV5_DeserializeAck_puback( void ) TEST_ASSERT_EQUAL_INT( MQTTSuccess, status ); TEST_ASSERT_EQUAL_INT( 1, packetIdentifier ); - /*Property length should be zero when request problem is set to false*/ + /* Property length should be zero when request problem is set to false*/ mqttPacketInfo.remainingLength = 24; status = MQTT_DeserializeAck( &mqttPacketInfo, &packetIdentifier, &ackInfo, &propBuffer, &properties ); TEST_ASSERT_EQUAL_INT( MQTTBadResponse, status ); requestProblem = true; properties.requestProblemInfo = requestProblem; - /*User properties not initialized.*/ + /* User properties not initialized. */ status = MQTT_DeserializeAck( &mqttPacketInfo, &packetIdentifier, &ackInfo, &propBuffer, &properties ); TEST_ASSERT_EQUAL_INT( MQTTBadResponse, status ); - /*Valid parameters.*/ + /* Valid parameters. */ pIndex = &buffer[ 3 ]; dummy = encodeVariableLengthUT( pIndex, 20 ); pIndex++; @@ -1904,11 +1998,11 @@ void test_MQTTV5_DeserializeAck_puback( void ) status = MQTT_DeserializeAck( &mqttPacketInfo, &packetIdentifier, &ackInfo, &propBuffer, &properties ); TEST_ASSERT_EQUAL_INT( MQTTSuccess, status ); - /*With NULL prop builder. */ + /* With NULL prop builder. */ status = MQTT_DeserializeAck( &mqttPacketInfo, &packetIdentifier, &ackInfo, NULL, &properties ); TEST_ASSERT_EQUAL_INT( MQTTSuccess, status ); - /*Invalid property id*/ + /* Invalid property id*/ pIndex = &buffer[ 3 ]; dummy = encodeVariableLengthUT( pIndex, 7 ); mqttPacketInfo.remainingLength = dummy + 7 + 3; @@ -1917,7 +2011,7 @@ void test_MQTTV5_DeserializeAck_puback( void ) status = MQTT_DeserializeAck( &mqttPacketInfo, &packetIdentifier, &ackInfo, &propBuffer, &properties ); TEST_ASSERT_EQUAL_INT( MQTTBadResponse, status ); - /*Invalid remaining length*/ + /* Invalid remaining length*/ pIndex = &buffer[ 3 ]; dummy = encodeVariableLengthUT( pIndex, 12 ); pIndex++; @@ -1925,8 +2019,7 @@ void test_MQTTV5_DeserializeAck_puback( void ) status = MQTT_DeserializeAck( &mqttPacketInfo, &packetIdentifier, &ackInfo, &propBuffer, &properties ); TEST_ASSERT_EQUAL_INT( MQTTBadResponse, status ); - - /*Invalid property length*/ + /* Invalid property length*/ pIndex = &buffer[ 3 ]; dummy = encodeVariableLengthUT( pIndex, 20971556356235 ); status = MQTT_DeserializeAck( &mqttPacketInfo, &packetIdentifier, &ackInfo, &propBuffer, &properties ); @@ -1953,7 +2046,7 @@ void test_MQTTV5_DeserializeAck_LogPuback() mqttPacketInfo.pRemainingData = buffer; mqttPacketInfo.type = MQTT_PACKET_TYPE_PUBACK; mqttPacketInfo.remainingLength = 3; - /*Validate all the correct reason codes.*/ + /* Validate all the correct reason codes. */ buffer[ 1 ] = 1; buffer[ 2 ] = MQTT_REASON_PUBACK_SUCCESS; status = MQTT_DeserializeAck( &mqttPacketInfo, &packetIdentifier, &ackInfo, &propBuffer, &properties ); @@ -2024,7 +2117,7 @@ void test_MQTTV5_DeserializeAck_Pubrel() mqttPacketInfo.pRemainingData = buffer; mqttPacketInfo.type = MQTT_PACKET_TYPE_PUBREL; mqttPacketInfo.remainingLength = 3; - /*Validate all the correct reason codes.*/ + /* Validate all the correct reason codes. */ buffer[ 1 ] = 1; buffer[ 2 ] = MQTT_REASON_PUBREL_SUCCESS; status = MQTT_DeserializeAck( &mqttPacketInfo, &packetIdentifier, &ackInfo, &propBuffer, &properties ); @@ -2035,22 +2128,22 @@ void test_MQTTV5_DeserializeAck_Pubrel() TEST_ASSERT_EQUAL_INT( MQTTSuccess, status ); TEST_ASSERT_EQUAL_UINT8( MQTT_REASON_PUBREL_PACKET_IDENTIFIER_NOT_FOUND, *ackInfo.reasonCode ); - /*Invalid reason code.*/ + /* Invalid reason code. */ buffer[ 2 ] = MQTT_REASON_CONNACK_BANNED; status = MQTT_DeserializeAck( &mqttPacketInfo, &packetIdentifier, &ackInfo, &propBuffer, &properties ); TEST_ASSERT_EQUAL_INT( MQTTBadResponse, status ); - /*Invalid reason code.*/ + /* Invalid reason code. */ buffer[ 2 ] = MQTT_REASON_DISCONNECT_DISCONNECT_WITH_WILL_MESSAGE; status = MQTT_DeserializeAck( &mqttPacketInfo, &packetIdentifier, &ackInfo, &propBuffer, &properties ); TEST_ASSERT_EQUAL_INT( MQTTBadResponse, status ); - /*Invalid packet id*/ + /* Invalid packet id*/ buffer[ 1 ] = 0; status = MQTT_DeserializeAck( &mqttPacketInfo, &packetIdentifier, &ackInfo, &propBuffer, &properties ); TEST_ASSERT_EQUAL_INT( MQTTBadResponse, status ); - /*Invalid packet type. */ + /* Invalid packet type. */ mqttPacketInfo.type = MQTT_PACKET_TYPE_DISCONNECT; status = MQTT_DeserializeAck( &mqttPacketInfo, &packetIdentifier, &ackInfo, &propBuffer, &properties ); TEST_ASSERT_EQUAL_INT( MQTTBadResponse, status ); @@ -2062,15 +2155,14 @@ void test_MQTTV5_DeserializeAck_Pubrel() TEST_ASSERT_EQUAL_INT( MQTTSuccess, status ); } - void test_MQTTV5_GetAckPacketSize() { MQTTStatus_t status; - size_t remainingLength; - size_t packetSize; + uint32_t remainingLength; + uint32_t packetSize; uint32_t maxPacketSize = 0U; - /*Invalid parameters*/ + /* Invalid parameters*/ status = MQTT_GetAckPacketSize( &remainingLength, &packetSize, maxPacketSize, 0 ); TEST_ASSERT_EQUAL_INT( MQTTBadParameter, status ); @@ -2080,25 +2172,29 @@ void test_MQTTV5_GetAckPacketSize() status = MQTT_GetAckPacketSize( &remainingLength, NULL, maxPacketSize, 0 ); TEST_ASSERT_EQUAL_INT( MQTTBadParameter, status ); - /*Max packet size cannot be 0*/ + /* Max packet size cannot be 0*/ status = MQTT_GetAckPacketSize( &remainingLength, NULL, maxPacketSize, 0 ); TEST_ASSERT_EQUAL_INT( MQTTBadParameter, status ); - /*Valid parameters*/ + /* Valid parameters*/ maxPacketSize = UINT32_MAX; status = MQTT_GetAckPacketSize( &remainingLength, &packetSize, maxPacketSize, 0 ); TEST_ASSERT_EQUAL_INT( MQTTSuccess, status ); - /*With properties*/ + /* With properties*/ status = MQTT_GetAckPacketSize( &remainingLength, &packetSize, maxPacketSize, 10 ); TEST_ASSERT_EQUAL_INT( MQTTSuccess, status ); - /*Packet size greater than max allowed.*/ + /* With invalid ack prop length. */ + status = MQTT_GetAckPacketSize( &remainingLength, &packetSize, maxPacketSize, MQTT_MAX_REMAINING_LENGTH + 1 ); + TEST_ASSERT_EQUAL_INT( MQTTBadParameter, status ); + + /* Packet size greater than max allowed. */ maxPacketSize = 2; status = MQTT_GetAckPacketSize( &remainingLength, &packetSize, maxPacketSize, 0 ); TEST_ASSERT_EQUAL_INT( MQTTBadParameter, status ); - /*Max packet size cannot be 0*/ + /* Max packet size cannot be 0*/ maxPacketSize = 0; status = MQTT_GetAckPacketSize( &remainingLength, &packetSize, maxPacketSize, 0 ); TEST_ASSERT_EQUAL_INT( MQTTBadParameter, status ); @@ -2108,16 +2204,15 @@ void test_MQTTV5_GetAckPacketSize() TEST_ASSERT_EQUAL_INT( MQTTBadParameter, status ); } - void test_MQTTV5_GetDisconnectPacketSize() { - size_t remainingLength; - size_t packetSize; + uint32_t remainingLength; + uint32_t packetSize; uint32_t maxPacketSize = 0U; MQTTStatus_t status; MQTTSuccessFailReasonCode_t reasonCode; - /*Invalid arguments*/ + /* Invalid arguments*/ reasonCode = MQTT_REASON_DISCONNECT_NORMAL_DISCONNECTION; status = MQTT_GetDisconnectPacketSize( NULL, &remainingLength, &packetSize, maxPacketSize, &reasonCode ); TEST_ASSERT_EQUAL_INT( MQTTBadParameter, status ); @@ -2130,7 +2225,7 @@ void test_MQTTV5_GetDisconnectPacketSize() status = MQTT_GetDisconnectPacketSize( NULL, &remainingLength, NULL, maxPacketSize, &reasonCode ); TEST_ASSERT_EQUAL_INT( MQTTBadParameter, status ); - /*Max packet size cannot be 0.*/ + /* Max packet size cannot be 0. */ reasonCode = MQTT_REASON_DISCONNECT_NORMAL_DISCONNECTION; status = MQTT_GetDisconnectPacketSize( NULL, &remainingLength, &packetSize, maxPacketSize, &reasonCode ); TEST_ASSERT_EQUAL_INT( MQTTBadParameter, status ); @@ -2145,22 +2240,22 @@ void test_MQTTV5_GetDisconnectPacketSize() status = MQTT_GetDisconnectPacketSize( NULL, &remainingLength, &packetSize, maxPacketSize, &reasonCode ); TEST_ASSERT_EQUAL_INT( MQTTBadParameter, status ); - /*Valid parameters*/ + /* Valid parameters*/ reasonCode = MQTT_REASON_DISCONNECT_DISCONNECT_WITH_WILL_MESSAGE; status = MQTT_GetDisconnectPacketSize( NULL, &remainingLength, &packetSize, maxPacketSize, &reasonCode ); TEST_ASSERT_EQUAL_INT( MQTTSuccess, status ); - /*Valid parameters*/ + /* Valid parameters*/ reasonCode = MQTT_REASON_DISCONNECT_PACKET_TOO_LARGE; status = MQTT_GetDisconnectPacketSize( NULL, &remainingLength, &packetSize, maxPacketSize, &reasonCode ); TEST_ASSERT_EQUAL_INT( MQTTSuccess, status ); - /*Invalid reason code. */ + /* Invalid reason code. */ reasonCode = MQTT_REASON_DISCONNECT_SERVER_BUSY; status = MQTT_GetDisconnectPacketSize( NULL, &remainingLength, &packetSize, maxPacketSize, &reasonCode ); TEST_ASSERT_EQUAL_INT( MQTTBadParameter, status ); - /*Max packet size lesser than packet size */ + /* Max packet size lesser than packet size */ MQTTPropBuilder_t propBuffer = { 0 }; uint8_t buf[ 10 ]; propBuffer.pBuffer = buf; @@ -2170,7 +2265,6 @@ void test_MQTTV5_GetDisconnectPacketSize() status = MQTT_GetDisconnectPacketSize( &propBuffer, &remainingLength, &packetSize, 6, &reasonCode ); TEST_ASSERT_EQUAL_INT( MQTTBadParameter, status ); - propBuffer.currentIndex = MQTT_MAX_REMAINING_LENGTH; /* Other fields do not have to be set as we only testing if the length of properties == max_remaining_length */ reasonCode = MQTT_REASON_DISCONNECT_NORMAL_DISCONNECTION; status = MQTT_GetDisconnectPacketSize( &propBuffer, &remainingLength, &packetSize, maxPacketSize, &reasonCode ); @@ -2182,8 +2276,6 @@ void test_MQTTV5_GetDisconnectPacketSize() TEST_ASSERT_EQUAL_INT( MQTTSuccess, status ); } - - void test_MQTTV5_DeserializeDisconnect() { MQTTReasonCodeInfo_t disconnectInfo; @@ -2194,11 +2286,11 @@ void test_MQTTV5_DeserializeDisconnect() MQTTPropBuilder_t propBuffer = { 0 }; memset( &disconnectInfo, 0x0, sizeof( disconnectInfo ) ); - /*Invalid parameters*/ + /* Invalid parameters*/ status = MQTT_DeserializeDisconnect( NULL, maxPacketSize, &disconnectInfo, &propBuffer ); TEST_ASSERT_EQUAL_INT( MQTTBadParameter, status ); - /*Remaining data not initialized.*/ + /* Remaining data not initialized. */ status = MQTT_DeserializeDisconnect( &packetInfo, maxPacketSize, &disconnectInfo, &propBuffer ); TEST_ASSERT_EQUAL_INT( MQTTBadParameter, status ); @@ -2206,22 +2298,21 @@ void test_MQTTV5_DeserializeDisconnect() status = MQTT_DeserializeDisconnect( &packetInfo, maxPacketSize, NULL, &propBuffer ); TEST_ASSERT_EQUAL_INT( MQTTBadParameter, status ); - /*Max packet size cannot be 0.*/ + /* Max packet size cannot be 0. */ status = MQTT_DeserializeDisconnect( &packetInfo, maxPacketSize, &disconnectInfo, &propBuffer ); TEST_ASSERT_EQUAL_INT( MQTTBadParameter, status ); maxPacketSize = 100; - /*Remaining length can be 0*/ + /* Remaining length can be 0*/ status = MQTT_DeserializeDisconnect( &packetInfo, maxPacketSize, &disconnectInfo, &propBuffer ); TEST_ASSERT_EQUAL_INT( MQTTSuccess, status ); - /*Remaining Length invalid. */ + /* Remaining Length invalid. */ packetInfo.remainingLength = 200; status = MQTT_DeserializeDisconnect( &packetInfo, maxPacketSize, &disconnectInfo, &propBuffer ); TEST_ASSERT_EQUAL_INT( MQTTBadResponse, status ); - - /*Invalid reason code.*/ + /* Invalid reason code. */ buffer[ 0 ] = MQTT_REASON_DISCONNECT_DISCONNECT_WITH_WILL_MESSAGE; status = MQTT_DeserializeDisconnect( &packetInfo, maxPacketSize, &disconnectInfo, &propBuffer ); TEST_ASSERT_EQUAL_INT( MQTTBadResponse, status ); @@ -2231,14 +2322,14 @@ void test_MQTTV5_DeserializeDisconnect() status = MQTT_DeserializeDisconnect( &packetInfo, maxPacketSize, &disconnectInfo, &propBuffer ); TEST_ASSERT_EQUAL_INT( MQTTSuccess, status ); - /*Property length is 0.*/ + /* Property length is 0. */ packetInfo.remainingLength = 2; pIndex = &buffer[ 1 ]; dummy = encodeVariableLengthUT( pIndex, 0 ); status = MQTT_DeserializeDisconnect( &packetInfo, maxPacketSize, &disconnectInfo, &propBuffer ); TEST_ASSERT_EQUAL_INT( MQTTSuccess, status ); - /*With properties*/ + /* With properties*/ buffer[ 0 ] = MQTT_REASON_DISCONNECT_NORMAL_DISCONNECTION; pIndex = &buffer[ 1 ]; packetInfo.remainingLength = 29; @@ -2250,13 +2341,13 @@ void test_MQTTV5_DeserializeDisconnect() status = MQTT_DeserializeDisconnect( &packetInfo, maxPacketSize, &disconnectInfo, &propBuffer ); TEST_ASSERT_EQUAL_INT( MQTTSuccess, status ); - /*Invalid reason code for incoming DISCONNECT packet. */ + /* Invalid reason code for incoming DISCONNECT packet. */ buffer[ 0 ] = MQTT_REASON_DISCONNECT_DISCONNECT_WITH_WILL_MESSAGE; status = MQTT_DeserializeDisconnect( &packetInfo, maxPacketSize, &disconnectInfo, &propBuffer ); TEST_ASSERT_EQUAL_INT( MQTTBadResponse, status ); buffer[ 0 ] = MQTT_REASON_DISCONNECT_NORMAL_DISCONNECTION; - /*Invalid property id.*/ + /* Invalid property id. */ pIndex = &buffer[ 1 ]; packetInfo.remainingLength = 9; dummy = encodeVariableLengthUT( pIndex, 7 ); @@ -2266,26 +2357,34 @@ void test_MQTTV5_DeserializeDisconnect() TEST_ASSERT_EQUAL_INT( MQTTBadResponse, status ); TEST_ASSERT_EQUAL_INT( 1, dummy ); - /*Invalid property length.*/ + /* Invalid property length. */ pIndex = &buffer[ 1 ]; packetInfo.remainingLength = 9; dummy = encodeVariableLengthUT( pIndex, 4 ); status = MQTT_DeserializeDisconnect( &packetInfo, maxPacketSize, &disconnectInfo, &propBuffer ); TEST_ASSERT_EQUAL_INT( MQTTBadResponse, status ); - /*Invalid property length.*/ + /* Invalid property length. */ buffer[ 1 ] = 0x81; buffer[ 2 ] = 0x00; status = MQTT_DeserializeDisconnect( &packetInfo, maxPacketSize, &disconnectInfo, &propBuffer ); TEST_ASSERT_EQUAL_INT( MQTTBadResponse, status ); - /*Property length is 0. */ + /* Property length is 0. */ buffer[ 0 ] = MQTT_REASON_DISCONNECT_NORMAL_DISCONNECTION; pIndex = &buffer[ 1 ]; packetInfo.remainingLength = 2; dummy = encodeVariableLengthUT( pIndex, 0 ); status = MQTT_DeserializeDisconnect( &packetInfo, maxPacketSize, &disconnectInfo, NULL ); TEST_ASSERT_EQUAL_INT( MQTTSuccess, status ); + + /* RemainingLength length is invalid. */ + buffer[ 0 ] = MQTT_REASON_DISCONNECT_NORMAL_DISCONNECTION; + pIndex = &buffer[ 1 ]; + packetInfo.remainingLength = MQTT_REMAINING_LENGTH_INVALID; + dummy = encodeVariableLengthUT( pIndex, 0 ); + status = MQTT_DeserializeDisconnect( &packetInfo, maxPacketSize, &disconnectInfo, NULL ); + TEST_ASSERT_EQUAL_INT( MQTTBadResponse, status ); } void test_MQTT_GetIncomingPacketTypeAndLength( void ) @@ -2310,8 +2409,8 @@ void test_MQTTV5_GetSubscribePacketSize( void ) { MQTTStatus_t status = MQTTSuccess; MQTTSubscribeInfo_t subscribeInfo; - size_t remainingLength = 0; - size_t packetSize = 0; + uint32_t remainingLength = 0; + uint32_t packetSize = 0; /** Verify Parameters */ @@ -2325,17 +2424,31 @@ void test_MQTTV5_GetSubscribePacketSize( void ) subscribeInfo.topicFilterLength = 13; subscribeInfo.pTopicFilter = "example/topic"; - /*Invalid max packet size*/ + /* Invalid max packet size*/ status = MQTT_GetSubscribePacketSize( &subscribeInfo, 1, NULL, &remainingLength, &packetSize, 0 ); TEST_ASSERT_EQUAL_INT( MQTTBadParameter, status ); + + MQTTPropBuilder_t propBuffer = { 0 }; + uint8_t buf[ 50 ]; + propBuffer.pBuffer = buf; + propBuffer.bufferLength = 50; + propBuffer.currentIndex = MQTT_MAX_REMAINING_LENGTH + 1; + /* Invalid current index. */ + status = MQTT_GetSubscribePacketSize( &subscribeInfo, 1, &propBuffer, &remainingLength, &packetSize, 100 ); + TEST_ASSERT_EQUAL_INT( MQTTBadParameter, status ); + + /* Invalid topic length. */ + subscribeInfo.topicFilterLength = 65536; + status = MQTT_GetSubscribePacketSize( &subscribeInfo, 1, NULL, &remainingLength, &packetSize, 100 ); + TEST_ASSERT_EQUAL_INT( MQTTBadParameter, status ); } void test_MQTTV5_GetSubscribePacketSize_HappyPath( void ) { MQTTStatus_t status = MQTTSuccess; MQTTSubscribeInfo_t subscribeInfo; - size_t remainingLength = 0; - size_t packetSize = 0; + uint32_t remainingLength = 0; + uint32_t packetSize = 0; subscribeInfo.pTopicFilter = TEST_TOPIC_NAME; subscribeInfo.topicFilterLength = TEST_TOPIC_NAME_LENGTH; @@ -2366,8 +2479,8 @@ void test_MQTTV5_GetSubscribePacketSize_MultipleSubscriptions( void ) { MQTTStatus_t status = MQTTSuccess; MQTTSubscribeInfo_t subscribeInfo[ 2 ]; - size_t remainingLength = 0; - size_t packetSize = 0; + uint32_t remainingLength = 0; + uint32_t packetSize = 0; subscribeInfo[ 0 ].pTopicFilter = TEST_TOPIC_NAME; subscribeInfo[ 0 ].topicFilterLength = TEST_TOPIC_NAME_LENGTH; @@ -2390,8 +2503,8 @@ void test_MQTTV5_GetSubscribePacketSize_MultipleSubscriptions( void ) void test_calculateSubscriptionPacketSizeV5( void ) { size_t subscriptionCount = 1; - size_t remainingLength = 0; - size_t packetSize = 0; + uint32_t remainingLength = 0; + uint32_t packetSize = 0; MQTTStatus_t status = MQTTSuccess; MQTTSubscribeInfo_t fourThousandSubscriptions[ 4096 ] = { 0 }; int i; @@ -2421,10 +2534,10 @@ void test_MQTT_SerializeSubscribe( void ) { MQTTSubscribeInfo_t subscriptionList; size_t subscriptionCount = 1; - size_t remainingLength = 0; + uint32_t remainingLength = 0; uint8_t buffer[ 25 + 2 * BUFFER_PADDING_LENGTH ]; size_t bufferSize = sizeof( buffer ) - 2 * BUFFER_PADDING_LENGTH; - size_t packetSize = bufferSize; + uint32_t packetSize = bufferSize; MQTTStatus_t status = MQTTSuccess; MQTTFixedBuffer_t fixedBuffer = { .pBuffer = &buffer[ BUFFER_PADDING_LENGTH ], .size = bufferSize }; uint8_t expectedPacket[ 100 ]; @@ -2589,7 +2702,7 @@ void test_MQTT_SerializeSubscribe( void ) TEST_ASSERT_EQUAL_INT( MQTTSuccess, status ); checkBufferOverflow( buffer, sizeof( buffer ) ); - /*test SerializeSubscribe with NULL property buffer. */ + /* test SerializeSubscribe with NULL property buffer. */ propBuffer.pBuffer = NULL; status = MQTT_SerializeSubscribe( &subscriptionList, subscriptionCount, @@ -2601,7 +2714,7 @@ void test_MQTT_SerializeSubscribe( void ) TEST_ASSERT_EQUAL_INT( MQTTSuccess, status ); checkBufferOverflow( buffer, sizeof( buffer ) ); - /*test MQTT_SerializeSubscribe subscription options. */ + /* test MQTT_SerializeSubscribe subscription options. */ subscriptionList.qos = MQTTQoS1; subscriptionList.pTopicFilter = "/example/topic"; subscriptionList.topicFilterLength = sizeof( "/example/topic" ); @@ -2638,10 +2751,10 @@ void test_MQTT_SerializeUnsubscribe( void ) { MQTTSubscribeInfo_t subscriptionList; size_t subscriptionCount = 1; - size_t remainingLength = 0; + uint32_t remainingLength = 0; uint8_t buffer[ 33 + 2 * BUFFER_PADDING_LENGTH ]; size_t bufferSize = sizeof( buffer ) - 2 * BUFFER_PADDING_LENGTH; - size_t packetSize = bufferSize; + uint32_t packetSize = bufferSize; MQTTStatus_t status = MQTTSuccess; MQTTFixedBuffer_t fixedBuffer = { .pBuffer = &buffer[ BUFFER_PADDING_LENGTH ], .size = bufferSize }; uint8_t expectedPacket[ 100 ]; @@ -2778,7 +2891,7 @@ void test_MQTT_SerializeUnsubscribe( void ) TEST_ASSERT_EQUAL_INT( MQTTSuccess, status ); checkBufferOverflow( buffer, sizeof( buffer ) ); - /*Test with null property buffer. */ + /* Test with null property buffer. */ propBuffer.pBuffer = NULL; status = MQTT_SerializeUnsubscribe( &subscriptionList, subscriptionCount, @@ -2860,7 +2973,7 @@ void test_MQTTV5_suback( void ) status = MQTT_DeserializeAck( &subackPacket, &packetIdentifier, &subackReasonCodes, &propBuffer, &properties ); TEST_ASSERT_EQUAL_INT( MQTTServerRefused, status ); - /*Invalid Property Length. */ + /* Invalid Property Length. */ subackPacket.remainingLength = 20; pIndex = &packetBufferNoProperties[ 4 ]; encodeVariableLengthUT( pIndex, 20971556356235 ); @@ -2878,8 +2991,8 @@ void test_MQTTV5_GetUnsubscribePacketSize( void ) { MQTTStatus_t status = MQTTSuccess; MQTTSubscribeInfo_t subscribeInfo = { 0 }; - size_t remainingLength = 0; - size_t packetSize = 0; + uint32_t remainingLength = 0; + uint32_t packetSize = 0; status = MQTT_GetUnsubscribePacketSize( NULL, 1, NULL, &remainingLength, &packetSize, MQTT_MAX_PACKET_SIZE ); TEST_ASSERT_EQUAL_INT( MQTTBadParameter, status ); @@ -2946,25 +3059,24 @@ void test_MQTTV5_DeserializeSuback( void ) status = MQTT_DeserializeAck( &mqttPacketInfo, &packetIdentifier, &subackReasonCodes, &propBuffer, &properties ); TEST_ASSERT_EQUAL_INT( MQTTBadResponse, status ); - /*Max Packet Size lesser than suback packet size*/ + /* Max Packet Size lesser than suback packet size*/ properties.maxPacketSize = 1U; status = MQTT_DeserializeAck( &mqttPacketInfo, &packetIdentifier, &subackReasonCodes, &propBuffer, &properties ); TEST_ASSERT_EQUAL_INT( MQTTBadResponse, status ); properties.maxPacketSize = MQTT_MAX_PACKET_SIZE; - /*Invalid Remaining Length*/ + /* Invalid Remaining Length*/ mqttPacketInfo.remainingLength = 2; status = MQTT_DeserializeAck( &mqttPacketInfo, &packetIdentifier, &subackReasonCodes, &propBuffer, &properties ); TEST_ASSERT_EQUAL_INT( MQTTBadResponse, status ); mqttPacketInfo.remainingLength = 14; - /*Invalid packet type*/ + /* Invalid packet type*/ buffer[ 1 ] = 0; status = MQTT_DeserializeAck( &mqttPacketInfo, &packetIdentifier, &subackReasonCodes, &propBuffer, &properties ); TEST_ASSERT_EQUAL_INT( MQTTBadResponse, status ); } - void test_incoming_publish2( void ) { MQTTPacketInfo_t mqttPacketInfo; @@ -2999,24 +3111,24 @@ void test_incoming_publish2( void ) status = MQTT_DeserializePublish( &mqttPacketInfo, &packetIdentifier, &publishIn, &propBuffer, 100, 100 ); TEST_ASSERT_EQUAL_INT( MQTTSuccess, status ); - /*Test with NULL Property Builder. */ + /* Test with NULL Property Builder. */ status = MQTT_DeserializePublish( &mqttPacketInfo, &packetIdentifier, &publishIn, NULL, 100, 100 ); TEST_ASSERT_EQUAL_INT( MQTTSuccess, status ); - /*Invalid property length*/ + /* Invalid property length*/ buffer[ 6 ] = 100; mqttPacketInfo.remainingLength = 46; status = MQTT_DeserializePublish( &mqttPacketInfo, &packetIdentifier, &publishIn, &propBuffer, 100, 100 ); TEST_ASSERT_EQUAL_INT( MQTTBadResponse, status ); - /*Only packet ID present*/ + /* Only packet ID present*/ mqttPacketInfo.type = ( MQTT_PACKET_TYPE_PUBLISH | 0x04 ); mqttPacketInfo.remainingLength = 9; buffer[ 6 ] = 0x00, buffer[ 7 ] = 0x01, buffer[ 8 ] = 0x00; status = MQTT_DeserializePublish( &mqttPacketInfo, &packetIdentifier, &publishInfo, &propBuffer, 100, 100 ); TEST_ASSERT_EQUAL_INT( MQTTSuccess, status ); - /*A property is received twice. */ + /* A property is received twice. */ buffer[ 6 ] = 12; pIndex = &buffer[ 7 ]; mqttPacketInfo.remainingLength = 21; @@ -3026,28 +3138,28 @@ void test_incoming_publish2( void ) status = MQTT_DeserializePublish( &mqttPacketInfo, &packetIdentifier, &publishIn, &propBuffer, 100, 100 ); TEST_ASSERT_EQUAL_INT( MQTTBadResponse, status ); - /*A property is received twice. */ + /* A property is received twice. */ pIndex = &buffer[ 7 ]; pIndex = serializeutf_8( pIndex, MQTT_CORRELATION_DATA_ID ); pIndex = serializeutf_8( pIndex, MQTT_CORRELATION_DATA_ID ); status = MQTT_DeserializePublish( &mqttPacketInfo, &packetIdentifier, &publishIn, &propBuffer, 100, 100 ); TEST_ASSERT_EQUAL_INT( MQTTBadResponse, status ); - /*A property is received twice. */ + /* A property is received twice. */ pIndex = &buffer[ 7 ]; pIndex = serializeuint_8( pIndex, MQTT_PAYLOAD_FORMAT_ID ); pIndex = serializeuint_8( pIndex, MQTT_PAYLOAD_FORMAT_ID ); status = MQTT_DeserializePublish( &mqttPacketInfo, &packetIdentifier, &publishIn, &propBuffer, 100, 100 ); TEST_ASSERT_EQUAL_INT( MQTTBadResponse, status ); - /*A property is received twice. */ + /* A property is received twice. */ pIndex = &buffer[ 7 ]; pIndex = serializeuint_16( pIndex, MQTT_TOPIC_ALIAS_ID ); pIndex = serializeuint_16( pIndex, MQTT_TOPIC_ALIAS_ID ); status = MQTT_DeserializePublish( &mqttPacketInfo, &packetIdentifier, &publishIn, &propBuffer, 100, 100 ); TEST_ASSERT_EQUAL_INT( MQTTBadResponse, status ); - /*A property is received twice. */ + /* A property is received twice. */ pIndex = &buffer[ 7 ]; buffer[ 6 ] = 10; mqttPacketInfo.remainingLength = 17; @@ -3056,7 +3168,7 @@ void test_incoming_publish2( void ) status = MQTT_DeserializePublish( &mqttPacketInfo, &packetIdentifier, &publishIn, &propBuffer, 100, 100 ); TEST_ASSERT_EQUAL_INT( MQTTBadResponse, status ); - /*Invalid topic alias. */ + /* Invalid topic alias. */ buffer[ 6 ] = 3; pIndex = &buffer[ 7 ]; mqttPacketInfo.remainingLength = 10; @@ -3065,7 +3177,7 @@ void test_incoming_publish2( void ) status = MQTT_DeserializePublish( &mqttPacketInfo, &packetIdentifier, &publishIn, &propBuffer, 100, topicAliasMax ); TEST_ASSERT_EQUAL_INT( MQTTBadResponse, status ); - /*Invalid property type. */ + /* Invalid property type. */ buffer[ 6 ] = 5; pIndex = &buffer[ 7 ]; pIndex = serializeuint_32( pIndex, MQTT_SESSION_EXPIRY_ID ); @@ -3073,7 +3185,7 @@ void test_incoming_publish2( void ) status = MQTT_DeserializePublish( &mqttPacketInfo, &packetIdentifier, &publishIn, &propBuffer, 100, topicAliasMax ); TEST_ASSERT_EQUAL_INT( MQTTBadResponse, status ); - /*Test Incoming Publish with Payload. */ + /* Test Incoming Publish with Payload. */ mqttPacketInfo.type = MQTT_PACKET_TYPE_PUBLISH; buffer[ 6 ] = 0x00; buffer[ 7 ] = 0x01; @@ -3082,7 +3194,7 @@ void test_incoming_publish2( void ) status = MQTT_DeserializePublish( &mqttPacketInfo, &packetIdentifier, &publishIn, NULL, 100, topicAliasMax ); TEST_ASSERT_EQUAL_INT( MQTTSuccess, status ); - /*Invalid Property Length. */ + /* Invalid Property Length. */ pIndex = &buffer[ 6 ]; mqttPacketInfo.remainingLength = 20; propertyLength = encodeVariableLengthUT( pIndex, 20971556356235 ); @@ -3145,7 +3257,6 @@ void test_Invalid_IncomingPublish( void ) buffer[ 1 ] = 0x01; buffer[ 2 ] = 0x61; - MQTTPublishInfo_t publishIn; ( void ) memset( &publishIn, 0x0, sizeof( publishIn ) ); status = MQTT_DeserializePublish( &mqttPacketInfo, &packetIdentifier, &publishIn, &propBuffer, 100, 100 ); @@ -3163,12 +3274,12 @@ void test_MQTT_SerializeDisconnect( void ) { uint8_t buffer[ 25 + 2 * BUFFER_PADDING_LENGTH ]; size_t bufferSize = sizeof( buffer ) - 2 * BUFFER_PADDING_LENGTH; - size_t packetSize = bufferSize; + uint32_t packetSize = bufferSize; MQTTFixedBuffer_t fixedBuffer = { .pBuffer = &buffer[ BUFFER_PADDING_LENGTH ], .size = bufferSize }; uint8_t expectedPacket[ 10 ] = { 0 }; uint8_t * pIterator = expectedPacket; MQTTStatus_t status = MQTTSuccess; - size_t remainingLength = 0; + uint32_t remainingLength = 0; /* Buffer size less than disconnect request fails. */ fixedBuffer.size = 1; @@ -3194,10 +3305,10 @@ void test_MQTT_SerializeDisconnect( void ) *pIterator++ = MQTT_PACKET_TYPE_DISCONNECT; pIterator += encodeVariableLengthUT( pIterator, remainingLength ); *pIterator++ = MQTT_REASON_DISCONNECT_NORMAL_DISCONNECTION; - *pIterator = 0; /*Property length is 0 */ + *pIterator = 0; /* Property length is 0 */ TEST_ASSERT_EQUAL_MEMORY( expectedPacket, &buffer[ BUFFER_PADDING_LENGTH ], packetSize ); - /*Test with properties. */ + /* Test with properties. */ MQTTPropBuilder_t propBuffer = { 0 }; uint8_t buf[ 10 ]; propBuffer.pBuffer = buf; @@ -3223,10 +3334,10 @@ void test_MQTT_SerializeDisconnect( void ) *pIterator++ = MQTT_PACKET_TYPE_DISCONNECT; pIterator += encodeVariableLengthUT( pIterator, remainingLength ); *pIterator++ = MQTT_REASON_DISCONNECT_NORMAL_DISCONNECTION; - *pIterator++ = 5; /*Property length is 2 */ - *pIterator++ = 0x11; /*Session Expiry ID*/ + *pIterator++ = 5; /* Property length is 2 */ + *pIterator++ = 0x11; /* Session Expiry ID*/ pIterator += 3; - *pIterator = 10; /*Session Expiry value */ + *pIterator = 10; /* Session Expiry value */ TEST_ASSERT_EQUAL_MEMORY( expectedPacket, &buffer[ BUFFER_PADDING_LENGTH ], packetSize ); /* test with null property buffer. */ @@ -3246,7 +3357,7 @@ void test_MQTT_SerializeDisconnect( void ) void test_MQTT_GetPingreqPacketSize( void ) { MQTTStatus_t status; - size_t packetSize; + uint32_t packetSize; /* Verify parameters. */ status = MQTT_GetPingreqPacketSize( NULL ); @@ -3434,7 +3545,7 @@ void test_MQTT_GetIncomingPacketTypeAndLength1( void ) void test_MQTT_SerializePublishHeaderWithoutTopic_BadInputs( void ) { MQTTPublishInfo_t publishInfo = { 0 }; - size_t remainingLength = 0; + uint32_t remainingLength = 0; uint8_t buffer[ 7 ]; MQTTStatus_t status = MQTTSuccess; size_t headerSize = 0; @@ -3470,7 +3581,7 @@ void test_MQTT_SerializePublishHeaderWithoutTopic_BadInputs( void ) void test_MQTT_SerializePublishHeaderWithoutTopic_AllNULL( void ) { MQTTPublishInfo_t publishInfo; - size_t remainingLength = 0; + uint32_t remainingLength = 0; uint8_t buffer[ 7 ]; MQTTStatus_t status = MQTTSuccess; size_t headerSize = 0; @@ -3492,7 +3603,6 @@ void test_MQTT_SerializePublishHeaderWithoutTopic_AllNULL( void ) TEST_ASSERT_EQUAL( buffer[ 2 ], 0U ); TEST_ASSERT_EQUAL( buffer[ 3 ], 0U ); - memset( &publishInfo, 0x00, sizeof( publishInfo ) ); status = MQTT_SerializePublishHeaderWithoutTopic( &publishInfo, @@ -3522,7 +3632,7 @@ void test_MQTT_SerializePublishHeaderWithoutTopic_AllNULL( void ) void test_MQTT_SerializePublishHeaderWithoutTopic_QoS1( void ) { MQTTPublishInfo_t publishInfo; - size_t remainingLength = 0; + uint32_t remainingLength = 0; uint8_t buffer[ 7 ]; MQTTStatus_t status = MQTTSuccess; size_t headerSize = 0; @@ -3554,7 +3664,7 @@ void test_MQTT_SerializePublishHeaderWithoutTopic_QoS1( void ) void test_MQTT_SerializePublishHeaderWithoutTopic_QoS2( void ) { MQTTPublishInfo_t publishInfo; - size_t remainingLength = 0; + uint32_t remainingLength = 0; uint8_t buffer[ 7 ]; MQTTStatus_t status = MQTTSuccess; size_t headerSize = 0; @@ -3586,7 +3696,7 @@ void test_MQTT_SerializePublishHeaderWithoutTopic_QoS2( void ) void test_MQTT_SerializePublishHeaderWithoutTopic_retain( void ) { MQTTPublishInfo_t publishInfo; - size_t remainingLength = 0; + uint32_t remainingLength = 0; uint8_t buffer[ 7 ]; MQTTStatus_t status = MQTTSuccess; size_t headerSize = 0; @@ -3618,7 +3728,7 @@ void test_MQTT_SerializePublishHeaderWithoutTopic_retain( void ) void test_MQTT_SerializePublishHeaderWithoutTopic_Duplicate( void ) { MQTTPublishInfo_t publishInfo; - size_t remainingLength = 0; + uint32_t remainingLength = 0; uint8_t buffer[ 7 ]; MQTTStatus_t status = MQTTSuccess; size_t headerSize = 0; @@ -3650,7 +3760,7 @@ void test_MQTT_SerializePublishHeaderWithoutTopic_Duplicate( void ) void test_MQTT_SerializePublishHeaderWithoutTopic_VariousFlagsSetTopicLength( void ) { MQTTPublishInfo_t publishInfo; - size_t remainingLength = 0; + uint32_t remainingLength = 0; uint8_t buffer[ 7 ]; MQTTStatus_t status = MQTTSuccess; size_t headerSize = 0; @@ -3685,12 +3795,12 @@ void test_MQTT_SerializePublishHeaderWithoutTopic_VariousFlagsSetTopicLength( vo void test_MQTT_SerializePublishHeader( void ) { MQTTPublishInfo_t publishInfo; - size_t remainingLength = 0; + uint32_t remainingLength = 0; uint8_t buffer[ 200 + 2 * BUFFER_PADDING_LENGTH ]; uint8_t expectedPacket[ 200 ]; uint8_t * pIterator; size_t bufferSize = sizeof( buffer ) - 2 * BUFFER_PADDING_LENGTH; - size_t packetSize = bufferSize; + uint32_t packetSize = bufferSize; MQTTStatus_t status = MQTTSuccess; MQTTFixedBuffer_t fixedBuffer = { .pBuffer = &buffer[ BUFFER_PADDING_LENGTH ], .size = bufferSize }; size_t headerSize = 0; @@ -3848,7 +3958,6 @@ void test_MQTT_SerializePublishHeader( void ) TEST_ASSERT_EQUAL_MEMORY( expectedPacket, &buffer[ BUFFER_PADDING_LENGTH ], packetSize ); checkBufferOverflow( buffer, sizeof( buffer ) ); - /* Again with QoS2 and dup. */ publishInfo.qos = MQTTQoS2; publishInfo.dup = true; @@ -3889,7 +3998,7 @@ void test_MQTT_SerializePublishHeader( void ) &headerSize ); TEST_ASSERT_EQUAL_INT( MQTTSuccess, status ); - /*test with null buffer. */ + /* test with null buffer. */ propBuffer.pBuffer = NULL; status = MQTT_SerializePublishHeader( &publishInfo, &propBuffer, @@ -3902,7 +4011,6 @@ void test_MQTT_SerializePublishHeader( void ) /* ========================================================================== */ - void test_MQTT_ProcessIncomingPacketTypeAndLength_PacketNULL( void ) { uint8_t pBuffer[ 100 ] = { 0 }; @@ -4063,7 +4171,6 @@ void test_MQTT_DeserializePublish( void ) uint16_t packetIdentifier; - memset( &mqttPacketInfo, 0x00, sizeof( mqttPacketInfo ) ); /* Verify parameters. */ @@ -4111,7 +4218,7 @@ void test_MQTT_DeserializePublish( void ) status = MQTT_DeserializePublish( &mqttPacketInfo, &packetIdentifier, &publishInfo, &propBuffer, 100, 100 ); TEST_ASSERT_EQUAL_INT( MQTTBadResponse, status ); - /*Invalid max packet size*/ + /* Invalid max packet size*/ status = MQTT_DeserializePublish( &mqttPacketInfo, &packetIdentifier, &publishInfo, &propBuffer, 1, 100 ); TEST_ASSERT_EQUAL_INT( MQTTBadResponse, status ); } @@ -4273,12 +4380,14 @@ void test_OptionalProperties( void ) mqttStatus = MQTTPropAdd_RequestProbInfo( &propBuilder, 1, NULL ); TEST_ASSERT_EQUAL_INT( MQTTBadParameter, mqttStatus ); - /*Test Auth Data before Auth Method.*/ + /* Test Auth Data before Auth Method. */ mqttStatus = MQTTPropAdd_AuthData( &propBuilder, "abc", 3, NULL ); TEST_ASSERT_EQUAL_INT( MQTTBadParameter, mqttStatus ); mqttStatus = MQTTPropAdd_AuthMethod( NULL, "abc", 3, NULL ); TEST_ASSERT_EQUAL_INT( MQTTBadParameter, mqttStatus ); + mqttStatus = MQTTPropAdd_AuthMethod( NULL, "abc", 65536, NULL ); + TEST_ASSERT_EQUAL_INT( MQTTBadParameter, mqttStatus ); mqttStatus = MQTTPropAdd_AuthMethod( &propBuilder, NULL, 3, NULL ); TEST_ASSERT_EQUAL_INT( MQTTBadParameter, mqttStatus ); mqttStatus = MQTTPropAdd_AuthMethod( &propBuilder, "abc", 0, NULL ); @@ -4287,9 +4396,28 @@ void test_OptionalProperties( void ) TEST_ASSERT_EQUAL_INT( MQTTBadParameter, mqttStatus ); mqttStatus = MQTTPropAdd_AuthMethod( &propBuilder, "abc", 3, NULL ); TEST_ASSERT_EQUAL_INT( MQTTSuccess, mqttStatus ); + + uint8_t buf1[ 65539 ]; + int8_t buf2[ 65539 ]; + memset( buf2, 0xAA, sizeof( buf2 ) ); + propBuilder.pBuffer = buf1; + propBuilder.bufferLength = 65539; + propBuilder.currentIndex = 0; + propBuilder.fieldSet = 0; + + mqttStatus = MQTTPropAdd_AuthMethod( &propBuilder, ( const char * ) buf2, 65535, NULL ); + TEST_ASSERT_EQUAL_INT( MQTTSuccess, mqttStatus ); mqttStatus = MQTTPropAdd_AuthMethod( &propBuilder, "abc", 3, NULL ); TEST_ASSERT_EQUAL_INT( MQTTBadParameter, mqttStatus ); + propBuilder.pBuffer = buf; + propBuilder.bufferLength = bufLength; + propBuilder.currentIndex = 0; + propBuilder.fieldSet = 0; + + mqttStatus = MQTTPropAdd_AuthMethod( &propBuilder, "abc", 3, NULL ); + TEST_ASSERT_EQUAL_INT( MQTTSuccess, mqttStatus ); + mqttStatus = MQTTPropAdd_AuthData( NULL, "abc", 3, NULL ); TEST_ASSERT_EQUAL_INT( MQTTBadParameter, mqttStatus ); mqttStatus = MQTTPropAdd_AuthData( &propBuilder, NULL, 3, NULL ); @@ -4558,7 +4686,6 @@ void test_MQTT_SerializeAck( void ) status = MQTT_SerializeAck( &fixedBuffer, MQTT_PACKET_TYPE_PUBACK, 0, NULL, NULL ); TEST_ASSERT_EQUAL_INT( status, MQTTBadParameter ); - status = MQTT_SerializeAck( &fixedBuffer, MQTT_PACKET_TYPE_SUBACK, 100, NULL, NULL ); TEST_ASSERT_EQUAL_INT( status, MQTTBadParameter ); @@ -4597,9 +4724,13 @@ void test_validatePublishProperties( void ) propBuilder.pBuffer = buffer; propBuilder.bufferLength = bufLength; - propBuilder.currentIndex = 0; + propBuilder.currentIndex = MQTT_REMAINING_LENGTH_INVALID; propBuilder.fieldSet = 0; + status = MQTT_ValidatePublishProperties( 1, &propBuilder, &topicAlias ); + TEST_ASSERT_EQUAL_INT( MQTTBadParameter, status ); + + propBuilder.currentIndex = 0; status = MQTT_ValidatePublishProperties( 1, &propBuilder, &topicAlias ); TEST_ASSERT_EQUAL_INT( MQTTSuccess, status ); @@ -4616,7 +4747,7 @@ void test_validatePublishProperties( void ) status = MQTT_ValidatePublishProperties( serverTopicAliasMax, &propBuilder, &topicAlias ); TEST_ASSERT_EQUAL_INT( MQTTSuccess, status ); - /*Property length field less than the actual length of the property.*/ + /* Property length field less than the actual length of the property. */ propBuilder.currentIndex = 2; status = MQTT_ValidatePublishProperties( serverTopicAliasMax, &propBuilder, &topicAlias ); TEST_ASSERT_EQUAL_INT( MQTTBadResponse, status ); @@ -4657,6 +4788,11 @@ void test_validateSubscribeProperties( void ) *pIndex = MQTT_SUBSCRIPTION_ID_ID; pIndex++; *pIndex = 2; + + propBuilder.currentIndex = MQTT_REMAINING_LENGTH_INVALID; + status = MQTT_ValidateSubscribeProperties( isSubIdAvailable, &propBuilder ); + TEST_ASSERT_EQUAL_INT( MQTTBadParameter, status ); + propBuilder.currentIndex = 2; status = MQTT_ValidateSubscribeProperties( isSubIdAvailable, &propBuilder ); TEST_ASSERT_EQUAL_INT( MQTTBadParameter, status ); @@ -4666,26 +4802,44 @@ void test_validateSubscribeProperties( void ) status = MQTT_ValidateSubscribeProperties( isSubIdAvailable, &propBuilder ); TEST_ASSERT_EQUAL_INT( MQTTSuccess, status ); - /*Validating user properties. */ + /* Validating user properties. */ pIndex = buffer; pIndex = serializeutf_8pair( pIndex ); propBuilder.currentIndex += 11; status = MQTT_ValidateSubscribeProperties( 1, &propBuilder ); TEST_ASSERT_EQUAL_INT( MQTTSuccess, status ); - /*Invalid property sent. */ + /* Invalid property sent. */ pIndex = serializeuint_8( pIndex, MQTT_PAYLOAD_FORMAT_ID ); propBuilder.currentIndex += 2; status = MQTT_ValidateSubscribeProperties( 1, &propBuilder ); TEST_ASSERT_EQUAL_INT( MQTTBadParameter, status ); - /*Invalid Subscription Id, exceeding 4 bytes. */ + /* Invalid Subscription Id, exceeding 4 bytes. */ pIndex = buffer; *pIndex++ = MQTT_SUBSCRIPTION_ID_ID; encodeVariableLengthUT( pIndex, 20971556356235 ); propBuilder.currentIndex = 10; status = MQTT_ValidateSubscribeProperties( 1, &propBuilder ); TEST_ASSERT_EQUAL_INT( MQTTBadResponse, status ); + + /* Invalid Subscription Id with value 0. */ + pIndex = buffer; + *pIndex++ = MQTT_SUBSCRIPTION_ID_ID; + encodeVariableLengthUT( pIndex, 0 ); + propBuilder.currentIndex = 10; + status = MQTT_ValidateSubscribeProperties( 1, &propBuilder ); + TEST_ASSERT_EQUAL_INT( MQTTBadParameter, status ); + + /* Invalid Subscription Id - included twice */ + pIndex = buffer; + *pIndex++ = MQTT_SUBSCRIPTION_ID_ID; + encodeVariableLengthUT( pIndex, 10 ); + *pIndex++ = MQTT_SUBSCRIPTION_ID_ID; + encodeVariableLengthUT( pIndex, 10 ); + propBuilder.currentIndex = 10; + status = MQTT_ValidateSubscribeProperties( 1, &propBuilder ); + TEST_ASSERT_EQUAL_INT( MQTTBadParameter, status ); } void test_getProps( void ) @@ -4736,16 +4890,16 @@ void test_getProps( void ) pIndex = serializeutf_8( pIndex, MQTT_AUTH_METHOD_ID ); pIndex = serializeutf_8( pIndex, MQTT_AUTH_DATA_ID ); - uint32_t propCurrentIndex = 0U; + size_t propCurrentIndex = 0U; uint16_t topicAlias; uint8_t payloadFormat; const char * pResponseTopic; - uint16_t responseTopicLength; + size_t responseTopicLength; const char * correlationData; - uint16_t correlationLength; + size_t correlationLength; uint32_t messageExpiry; const char * pContentType; - uint16_t contentTypeLength; + size_t contentTypeLength; uint32_t subscriptionId; uint32_t sessionExpiry; uint16_t aliasMax; @@ -4754,20 +4908,20 @@ void test_getProps( void ) uint8_t retainAvailable; uint32_t maxPacketSize; const char * pClientId; - uint16_t clientIdLength; + size_t clientIdLength; uint8_t wildcard; uint8_t subAvailable; uint8_t propertyId; const char * pReasonString; - uint16_t reasonStringLength; + size_t reasonStringLength; uint8_t sharedSubAvailable; uint16_t serverKeepAlive; const char * pResponseInfo; - uint16_t responseInfoLength; + size_t responseInfoLength; const char * pAuthMethod; - uint16_t authMethodLength; + size_t authMethodLength; const char * pAuthData; - uint16_t authDataLength; + size_t authDataLength; MQTTUserProperty_t userProp; size_t counter = 0U; @@ -4996,9 +5150,9 @@ void test_getProps_decodeFailure( void ) uint32_t sessionExpiry; uint32_t maxPacketSize; const char * string; - uint16_t stringLength; + size_t stringLength; MQTTUserProperty_t userProp; - uint32_t propCurrentIndex = 0U; + size_t propCurrentIndex = 0U; uint8_t buffer[ 500 ] = { 0 }; size_t bufLength = 500; @@ -5204,20 +5358,26 @@ void test_ValidateDisconnectProperties( void ) status = MQTT_ValidateDisconnectProperties( 10, &propBuffer ); TEST_ASSERT_EQUAL( MQTTSuccess, status ); - /*Disconnect Session Expiry non-zero while Connect Session Expiry was zero.*/ + /* Disconnect Session Expiry non-zero while Connect Session Expiry was zero. */ status = MQTT_ValidateDisconnectProperties( 0, &propBuffer ); TEST_ASSERT_EQUAL( MQTTBadParameter, status ); - /*Invalid property is sent in the disconnect. */ + /* Invalid property is sent in the disconnect. */ propBuffer.currentIndex = 28; status = MQTT_ValidateDisconnectProperties( 10, &propBuffer ); TEST_ASSERT_EQUAL( MQTTBadParameter, status ); - /*Invalid property length. */ + /* Invalid property length. */ propBuffer.currentIndex = 2; status = MQTT_ValidateDisconnectProperties( 10, &propBuffer ); TEST_ASSERT_EQUAL( MQTTBadResponse, status ); + buf[ 0 ] = MQTT_SESSION_EXPIRY_ID; + buf[ 1 ] = 0, buf[ 2 ] = 0, buf[ 3 ] = 0, buf[ 4 ] = 0; + propBuffer.currentIndex = MQTT_REMAINING_LENGTH_INVALID; + status = MQTT_ValidateDisconnectProperties( 0, &propBuffer ); + TEST_ASSERT_EQUAL( MQTTBadParameter, status ); + buf[ 0 ] = MQTT_SESSION_EXPIRY_ID; buf[ 1 ] = 0, buf[ 2 ] = 0, buf[ 3 ] = 0, buf[ 4 ] = 0; propBuffer.currentIndex = 5; @@ -5232,7 +5392,7 @@ void test_ValidateUnsubscribeProperties( void ) status = MQTT_ValidateUnsubscribeProperties( NULL ); TEST_ASSERT_EQUAL( MQTTSuccess, status ); - MQTTPropBuilder_t propBuffer; + MQTTPropBuilder_t propBuffer = { 0 }; propBuffer.pBuffer = NULL; status = MQTT_ValidateUnsubscribeProperties( &propBuffer ); TEST_ASSERT_EQUAL( MQTTSuccess, status ); @@ -5240,17 +5400,22 @@ void test_ValidateUnsubscribeProperties( void ) uint8_t buf[ 50 ]; propBuffer.pBuffer = buf; propBuffer.bufferLength = 50; - propBuffer.currentIndex = 13; uint8_t * pIndex = buf; pIndex = serializeutf_8pair( pIndex ); pIndex = serializeuint_32( pIndex, MQTT_SESSION_EXPIRY_ID ); + /* Invalid property length. */ + propBuffer.currentIndex = MQTT_REMAINING_LENGTH_INVALID; + status = MQTT_ValidateUnsubscribeProperties( &propBuffer ); + TEST_ASSERT_EQUAL( MQTTBadParameter, status ); + + propBuffer.currentIndex = 13; status = MQTT_ValidateUnsubscribeProperties( &propBuffer ); TEST_ASSERT_EQUAL( MQTTSuccess, status ); propBuffer.currentIndex = 18; - /*Invalid property send in the unsubscribe.*/ + /* Invalid property send in the unsubscribe. */ status = MQTT_ValidateUnsubscribeProperties( &propBuffer ); TEST_ASSERT_EQUAL( MQTTBadParameter, status ); } @@ -5270,6 +5435,10 @@ void test_ValidateWillProperties( void ) uint8_t buf[ 50 ]; propBuffer.pBuffer = buf; propBuffer.bufferLength = 50; + propBuffer.currentIndex = MQTT_REMAINING_LENGTH_INVALID; + status = MQTT_ValidateWillProperties( &propBuffer ); + TEST_ASSERT_EQUAL( MQTTBadParameter, status ); + propBuffer.currentIndex = 32; uint8_t * pIndex = buf; @@ -5284,7 +5453,7 @@ void test_ValidateWillProperties( void ) TEST_ASSERT_EQUAL( MQTTSuccess, status ); propBuffer.currentIndex = 37; - /*Invalid property sent in LWT. */ + /* Invalid property sent in LWT. */ status = MQTT_ValidateWillProperties( &propBuffer ); TEST_ASSERT_EQUAL( MQTTBadResponse, status ); @@ -5390,16 +5559,22 @@ void test_ValidateWillProperties( void ) void test_ValidatePublishAckProperties( void ) { MQTTStatus_t status = MQTTSuccess; + uint8_t buf[ 50 ]; status = MQTT_ValidatePublishAckProperties( NULL ); TEST_ASSERT_EQUAL( MQTTSuccess, status ); - MQTTPropBuilder_t propBuffer; + MQTTPropBuilder_t propBuffer = { 0 }; + propBuffer.pBuffer = buf; + propBuffer.currentIndex = MQTT_REMAINING_LENGTH_INVALID; + status = MQTT_ValidatePublishAckProperties( &propBuffer ); + TEST_ASSERT_EQUAL( MQTTBadParameter, status ); + propBuffer.pBuffer = NULL; + propBuffer.currentIndex = 0; status = MQTT_ValidatePublishAckProperties( &propBuffer ); TEST_ASSERT_EQUAL( MQTTSuccess, status ); - uint8_t buf[ 50 ]; propBuffer.pBuffer = buf; propBuffer.bufferLength = 50; propBuffer.currentIndex = 20; @@ -5428,6 +5603,9 @@ void test_Mqtt_PropertyBuilder_Init( void ) mqttStatus = MQTTPropertyBuilder_Init( &( ackPropsBuilder ), ackPropsBuf, ackPropsBufLength ); TEST_ASSERT_EQUAL( MQTTSuccess, mqttStatus ); + mqttStatus = MQTTPropertyBuilder_Init( &( ackPropsBuilder ), ackPropsBuf, MQTT_REMAINING_LENGTH_INVALID ); + TEST_ASSERT_EQUAL( MQTTBadParameter, mqttStatus ); + mqttStatus = MQTTPropertyBuilder_Init( NULL, ackPropsBuf, ackPropsBufLength ); TEST_ASSERT_EQUAL( MQTTBadParameter, mqttStatus ); @@ -5446,7 +5624,7 @@ void test_decodeSubackPropertyLength( void ) buffer[ 0 ] = 0; buffer[ 1 ] = 1; - buffer[ 2 ] = 0; /*Length of the properties is 0. */ + buffer[ 2 ] = 0; /* Length of the properties is 0. */ buffer[ 3 ] = 0x00; buffer[ 4 ] = 0x01; buffer[ 5 ] = 0x02; @@ -5464,7 +5642,7 @@ void test_decodeSubackPropertyLength( void ) TEST_ASSERT_EQUAL( MQTTSuccess, status ); TEST_ASSERT_EQUAL_INT( 3, propertyLength ); - /*Invalid remaining length. */ + /* Invalid remaining length. */ status = decodeSubackPropertyLength( &buffer[ 2 ], 2, &propertyLength ); TEST_ASSERT_EQUAL( MQTTBadResponse, status ); @@ -5519,6 +5697,14 @@ void test_MQTT_ValidateConnectProperties( void ) TEST_ASSERT_EQUAL( MQTTSuccess, status ); TEST_ASSERT_EQUAL( false, isRequestProblemInfoSet ); + /* Test 4.1: properties with invalid length. */ + propBuilder.pBuffer = buf; + propBuilder.bufferLength = 200; + propBuilder.currentIndex = MQTT_REMAINING_LENGTH_INVALID; + isRequestProblemInfoSet = true; /* Should be set to false */ + status = MQTT_ValidateConnectProperties( &propBuilder, &isRequestProblemInfoSet ); + TEST_ASSERT_EQUAL( MQTTBadParameter, status ); + /* Test 5: Valid MQTT_SESSION_EXPIRY_ID */ pIndex = buf; pIndex = serializeuint_32( pIndex, MQTT_SESSION_EXPIRY_ID ); @@ -5898,7 +6084,6 @@ void test_MQTT_ValidateConnectProperties_DecodeErrors( void ) TEST_ASSERT_EQUAL( MQTTBadResponse, status ); } - /* Comprehensive tests for validateReasonCodeForAck (tested via MQTT_SerializeAck) */ void test_validateReasonCodeForAck_PUBACK( void ) @@ -6447,7 +6632,7 @@ void test_getAckPacketSize_AllPacketTypes( void ) void test_MQTT_SkipNextProperty_NullPropertyBuilder( void ) { MQTTStatus_t status; - uint32_t currentIndex = 0; + size_t currentIndex = 0; status = MQTT_SkipNextProperty( NULL, ¤tIndex ); @@ -6478,7 +6663,7 @@ void test_MQTT_SkipNextProperty_NullBuffer( void ) { MQTTPropBuilder_t propBuilder = { 0 }; MQTTStatus_t status; - uint32_t currentIndex = 0; + size_t currentIndex = 0; propBuilder.pBuffer = NULL; propBuilder.bufferLength = MQTT_TEST_BUFFER_LENGTH; @@ -6500,7 +6685,7 @@ void test_MQTT_SkipNextProperty_IndexAtEnd( void ) uint8_t testBuffer[ MQTT_TEST_BUFFER_LENGTH ]; MQTTPropBuilder_t propBuilder = { 0 }; MQTTStatus_t status; - uint32_t currentIndex = 0; + size_t currentIndex = 0; propBuilder.pBuffer = testBuffer; propBuilder.bufferLength = MQTT_TEST_BUFFER_LENGTH; @@ -6519,7 +6704,7 @@ void test_MQTT_SkipNextProperty_IndexBeyondEnd( void ) uint8_t testBuffer[ MQTT_TEST_BUFFER_LENGTH ]; MQTTPropBuilder_t propBuilder = { 0 }; MQTTStatus_t status; - uint32_t currentIndex = 10; + size_t currentIndex = 10; propBuilder.pBuffer = testBuffer; propBuilder.bufferLength = MQTT_TEST_BUFFER_LENGTH; @@ -6542,7 +6727,7 @@ void test_MQTT_SkipNextProperty_UnknownPropertyId( void ) uint8_t testBuffer[ MQTT_TEST_BUFFER_LENGTH ]; MQTTPropBuilder_t propBuilder = { 0 }; MQTTStatus_t status; - uint32_t currentIndex = 0; + size_t currentIndex = 0; propBuilder.pBuffer = testBuffer; propBuilder.bufferLength = MQTT_TEST_BUFFER_LENGTH; @@ -6568,7 +6753,7 @@ void test_MQTT_SkipNextProperty_SessionExpiry( void ) uint8_t testBuffer[ MQTT_TEST_BUFFER_LENGTH ]; MQTTPropBuilder_t propBuilder = { 0 }; MQTTStatus_t status; - uint32_t currentIndex = 0; + size_t currentIndex = 0; uint8_t * pIndex = testBuffer; propBuilder.pBuffer = testBuffer; @@ -6597,7 +6782,7 @@ void test_MQTT_SkipNextProperty_MaxPacketSize( void ) uint8_t testBuffer[ MQTT_TEST_BUFFER_LENGTH ]; MQTTPropBuilder_t propBuilder = { 0 }; MQTTStatus_t status; - uint32_t currentIndex = 0; + size_t currentIndex = 0; uint8_t * pIndex = testBuffer; propBuilder.pBuffer = testBuffer; @@ -6625,7 +6810,7 @@ void test_MQTT_SkipNextProperty_WillDelay( void ) uint8_t testBuffer[ MQTT_TEST_BUFFER_LENGTH ]; MQTTPropBuilder_t propBuilder = { 0 }; MQTTStatus_t status; - uint32_t currentIndex = 0; + size_t currentIndex = 0; uint8_t * pIndex = testBuffer; propBuilder.pBuffer = testBuffer; @@ -6653,7 +6838,7 @@ void test_MQTT_SkipNextProperty_MessageExpiry( void ) uint8_t testBuffer[ MQTT_TEST_BUFFER_LENGTH ]; MQTTPropBuilder_t propBuilder = { 0 }; MQTTStatus_t status; - uint32_t currentIndex = 0; + size_t currentIndex = 0; uint8_t * pIndex = testBuffer; propBuilder.pBuffer = testBuffer; @@ -6681,7 +6866,7 @@ void test_MQTT_SkipNextProperty_Uint32_InsufficientBuffer( void ) uint8_t testBuffer[ MQTT_TEST_BUFFER_LENGTH ]; MQTTPropBuilder_t propBuilder = { 0 }; MQTTStatus_t status; - uint32_t currentIndex = 0; + size_t currentIndex = 0; propBuilder.pBuffer = testBuffer; propBuilder.bufferLength = MQTT_TEST_BUFFER_LENGTH; @@ -6707,7 +6892,7 @@ void test_MQTT_SkipNextProperty_ReceiveMax( void ) uint8_t testBuffer[ MQTT_TEST_BUFFER_LENGTH ]; MQTTPropBuilder_t propBuilder = { 0 }; MQTTStatus_t status; - uint32_t currentIndex = 0; + size_t currentIndex = 0; uint8_t * pIndex = testBuffer; propBuilder.pBuffer = testBuffer; @@ -6733,7 +6918,7 @@ void test_MQTT_SkipNextProperty_TopicAliasMax( void ) uint8_t testBuffer[ MQTT_TEST_BUFFER_LENGTH ]; MQTTPropBuilder_t propBuilder = { 0 }; MQTTStatus_t status; - uint32_t currentIndex = 0; + size_t currentIndex = 0; uint8_t * pIndex = testBuffer; propBuilder.pBuffer = testBuffer; @@ -6759,7 +6944,7 @@ void test_MQTT_SkipNextProperty_TopicAlias( void ) uint8_t testBuffer[ MQTT_TEST_BUFFER_LENGTH ]; MQTTPropBuilder_t propBuilder = { 0 }; MQTTStatus_t status; - uint32_t currentIndex = 0; + size_t currentIndex = 0; uint8_t * pIndex = testBuffer; propBuilder.pBuffer = testBuffer; @@ -6785,7 +6970,7 @@ void test_MQTT_SkipNextProperty_ServerKeepAlive( void ) uint8_t testBuffer[ MQTT_TEST_BUFFER_LENGTH ]; MQTTPropBuilder_t propBuilder = { 0 }; MQTTStatus_t status; - uint32_t currentIndex = 0; + size_t currentIndex = 0; uint8_t * pIndex = testBuffer; propBuilder.pBuffer = testBuffer; @@ -6811,7 +6996,7 @@ void test_MQTT_SkipNextProperty_Uint16_InsufficientBuffer( void ) uint8_t testBuffer[ MQTT_TEST_BUFFER_LENGTH ]; MQTTPropBuilder_t propBuilder = { 0 }; MQTTStatus_t status; - uint32_t currentIndex = 0; + size_t currentIndex = 0; propBuilder.pBuffer = testBuffer; propBuilder.bufferLength = MQTT_TEST_BUFFER_LENGTH; @@ -6837,7 +7022,7 @@ void test_MQTT_SkipNextProperty_RequestResponse( void ) uint8_t testBuffer[ MQTT_TEST_BUFFER_LENGTH ]; MQTTPropBuilder_t propBuilder = { 0 }; MQTTStatus_t status; - uint32_t currentIndex = 0; + size_t currentIndex = 0; uint8_t * pIndex = testBuffer; propBuilder.pBuffer = testBuffer; @@ -6862,7 +7047,7 @@ void test_MQTT_SkipNextProperty_RequestProblem( void ) uint8_t testBuffer[ MQTT_TEST_BUFFER_LENGTH ]; MQTTPropBuilder_t propBuilder = { 0 }; MQTTStatus_t status; - uint32_t currentIndex = 0; + size_t currentIndex = 0; uint8_t * pIndex = testBuffer; propBuilder.pBuffer = testBuffer; @@ -6887,7 +7072,7 @@ void test_MQTT_SkipNextProperty_PayloadFormat( void ) uint8_t testBuffer[ MQTT_TEST_BUFFER_LENGTH ]; MQTTPropBuilder_t propBuilder = { 0 }; MQTTStatus_t status; - uint32_t currentIndex = 0; + size_t currentIndex = 0; uint8_t * pIndex = testBuffer; propBuilder.pBuffer = testBuffer; @@ -6912,7 +7097,7 @@ void test_MQTT_SkipNextProperty_MaxQos( void ) uint8_t testBuffer[ MQTT_TEST_BUFFER_LENGTH ]; MQTTPropBuilder_t propBuilder = { 0 }; MQTTStatus_t status; - uint32_t currentIndex = 0; + size_t currentIndex = 0; uint8_t * pIndex = testBuffer; propBuilder.pBuffer = testBuffer; @@ -6937,7 +7122,7 @@ void test_MQTT_SkipNextProperty_RetainAvailable( void ) uint8_t testBuffer[ MQTT_TEST_BUFFER_LENGTH ]; MQTTPropBuilder_t propBuilder = { 0 }; MQTTStatus_t status; - uint32_t currentIndex = 0; + size_t currentIndex = 0; uint8_t * pIndex = testBuffer; propBuilder.pBuffer = testBuffer; @@ -6962,7 +7147,7 @@ void test_MQTT_SkipNextProperty_Wildcard( void ) uint8_t testBuffer[ MQTT_TEST_BUFFER_LENGTH ]; MQTTPropBuilder_t propBuilder = { 0 }; MQTTStatus_t status; - uint32_t currentIndex = 0; + size_t currentIndex = 0; uint8_t * pIndex = testBuffer; propBuilder.pBuffer = testBuffer; @@ -6987,7 +7172,7 @@ void test_MQTT_SkipNextProperty_SubAvailable( void ) uint8_t testBuffer[ MQTT_TEST_BUFFER_LENGTH ]; MQTTPropBuilder_t propBuilder = { 0 }; MQTTStatus_t status; - uint32_t currentIndex = 0; + size_t currentIndex = 0; uint8_t * pIndex = testBuffer; propBuilder.pBuffer = testBuffer; @@ -7012,7 +7197,7 @@ void test_MQTT_SkipNextProperty_SharedSub( void ) uint8_t testBuffer[ MQTT_TEST_BUFFER_LENGTH ]; MQTTPropBuilder_t propBuilder = { 0 }; MQTTStatus_t status; - uint32_t currentIndex = 0; + size_t currentIndex = 0; uint8_t * pIndex = testBuffer; propBuilder.pBuffer = testBuffer; @@ -7037,7 +7222,7 @@ void test_MQTT_SkipNextProperty_Uint8_InsufficientBuffer( void ) uint8_t testBuffer[ MQTT_TEST_BUFFER_LENGTH ]; MQTTPropBuilder_t propBuilder = { 0 }; MQTTStatus_t status; - uint32_t currentIndex = 0; + size_t currentIndex = 0; propBuilder.pBuffer = testBuffer; propBuilder.bufferLength = MQTT_TEST_BUFFER_LENGTH; @@ -7063,7 +7248,7 @@ void test_MQTT_SkipNextProperty_AuthMethod( void ) uint8_t testBuffer[ MQTT_TEST_BUFFER_LENGTH ]; MQTTPropBuilder_t propBuilder = { 0 }; MQTTStatus_t status; - uint32_t currentIndex = 0; + size_t currentIndex = 0; uint8_t * pIndex = testBuffer; propBuilder.pBuffer = testBuffer; @@ -7088,7 +7273,7 @@ void test_MQTT_SkipNextProperty_ContentType( void ) uint8_t testBuffer[ MQTT_TEST_BUFFER_LENGTH ]; MQTTPropBuilder_t propBuilder = { 0 }; MQTTStatus_t status; - uint32_t currentIndex = 0; + size_t currentIndex = 0; uint8_t * pIndex = testBuffer; propBuilder.pBuffer = testBuffer; @@ -7113,7 +7298,7 @@ void test_MQTT_SkipNextProperty_ResponseTopic( void ) uint8_t testBuffer[ MQTT_TEST_BUFFER_LENGTH ]; MQTTPropBuilder_t propBuilder = { 0 }; MQTTStatus_t status; - uint32_t currentIndex = 0; + size_t currentIndex = 0; uint8_t * pIndex = testBuffer; propBuilder.pBuffer = testBuffer; @@ -7138,7 +7323,7 @@ void test_MQTT_SkipNextProperty_AssignedClientId( void ) uint8_t testBuffer[ MQTT_TEST_BUFFER_LENGTH ]; MQTTPropBuilder_t propBuilder = { 0 }; MQTTStatus_t status; - uint32_t currentIndex = 0; + size_t currentIndex = 0; uint8_t * pIndex = testBuffer; propBuilder.pBuffer = testBuffer; @@ -7163,7 +7348,7 @@ void test_MQTT_SkipNextProperty_ReasonString( void ) uint8_t testBuffer[ MQTT_TEST_BUFFER_LENGTH ]; MQTTPropBuilder_t propBuilder = { 0 }; MQTTStatus_t status; - uint32_t currentIndex = 0; + size_t currentIndex = 0; uint8_t * pIndex = testBuffer; propBuilder.pBuffer = testBuffer; @@ -7188,7 +7373,7 @@ void test_MQTT_SkipNextProperty_ResponseInfo( void ) uint8_t testBuffer[ MQTT_TEST_BUFFER_LENGTH ]; MQTTPropBuilder_t propBuilder = { 0 }; MQTTStatus_t status; - uint32_t currentIndex = 0; + size_t currentIndex = 0; uint8_t * pIndex = testBuffer; propBuilder.pBuffer = testBuffer; @@ -7213,7 +7398,7 @@ void test_MQTT_SkipNextProperty_ServerRef( void ) uint8_t testBuffer[ MQTT_TEST_BUFFER_LENGTH ]; MQTTPropBuilder_t propBuilder = { 0 }; MQTTStatus_t status; - uint32_t currentIndex = 0; + size_t currentIndex = 0; uint8_t * pIndex = testBuffer; propBuilder.pBuffer = testBuffer; @@ -7238,7 +7423,7 @@ void test_MQTT_SkipNextProperty_AuthData( void ) uint8_t testBuffer[ MQTT_TEST_BUFFER_LENGTH ]; MQTTPropBuilder_t propBuilder = { 0 }; MQTTStatus_t status; - uint32_t currentIndex = 0; + size_t currentIndex = 0; uint8_t * pIndex = testBuffer; propBuilder.pBuffer = testBuffer; @@ -7263,7 +7448,7 @@ void test_MQTT_SkipNextProperty_CorrelationData( void ) uint8_t testBuffer[ MQTT_TEST_BUFFER_LENGTH ]; MQTTPropBuilder_t propBuilder = { 0 }; MQTTStatus_t status; - uint32_t currentIndex = 0; + size_t currentIndex = 0; uint8_t * pIndex = testBuffer; propBuilder.pBuffer = testBuffer; @@ -7288,7 +7473,7 @@ void test_MQTT_SkipNextProperty_Utf8_InsufficientBufferForLength( void ) uint8_t testBuffer[ MQTT_TEST_BUFFER_LENGTH ]; MQTTPropBuilder_t propBuilder = { 0 }; MQTTStatus_t status; - uint32_t currentIndex = 0; + size_t currentIndex = 0; propBuilder.pBuffer = testBuffer; propBuilder.bufferLength = MQTT_TEST_BUFFER_LENGTH; @@ -7310,7 +7495,7 @@ void test_MQTT_SkipNextProperty_Utf8_InsufficientBufferForData( void ) uint8_t testBuffer[ MQTT_TEST_BUFFER_LENGTH ]; MQTTPropBuilder_t propBuilder = { 0 }; MQTTStatus_t status; - uint32_t currentIndex = 0; + size_t currentIndex = 0; uint8_t * pIndex = testBuffer; propBuilder.pBuffer = testBuffer; @@ -7340,7 +7525,7 @@ void test_MQTT_SkipNextProperty_UserProperty( void ) uint8_t testBuffer[ MQTT_TEST_BUFFER_LENGTH ]; MQTTPropBuilder_t propBuilder = { 0 }; MQTTStatus_t status; - uint32_t currentIndex = 0; + size_t currentIndex = 0; uint8_t * pIndex = testBuffer; propBuilder.pBuffer = testBuffer; @@ -7366,7 +7551,7 @@ void test_MQTT_SkipNextProperty_UserProperty_InsufficientBufferForKey( void ) uint8_t testBuffer[ MQTT_TEST_BUFFER_LENGTH ]; MQTTPropBuilder_t propBuilder = { 0 }; MQTTStatus_t status; - uint32_t currentIndex = 0; + size_t currentIndex = 0; propBuilder.pBuffer = testBuffer; propBuilder.bufferLength = MQTT_TEST_BUFFER_LENGTH; @@ -7391,7 +7576,7 @@ void test_MQTT_SkipNextProperty_UserProperty_InsufficientBufferForValue( void ) uint8_t testBuffer[ MQTT_TEST_BUFFER_LENGTH ]; MQTTPropBuilder_t propBuilder = { 0 }; MQTTStatus_t status; - uint32_t currentIndex = 0; + size_t currentIndex = 0; uint8_t * pIndex = testBuffer; propBuilder.pBuffer = testBuffer; @@ -7422,7 +7607,7 @@ void test_MQTT_SkipNextProperty_SubscriptionId_OneByte( void ) uint8_t testBuffer[ MQTT_TEST_BUFFER_LENGTH ]; MQTTPropBuilder_t propBuilder = { 0 }; MQTTStatus_t status; - uint32_t currentIndex = 0; + size_t currentIndex = 0; uint8_t * pIndex = testBuffer; propBuilder.pBuffer = testBuffer; @@ -7447,7 +7632,7 @@ void test_MQTT_SkipNextProperty_SubscriptionId_TwoBytes( void ) uint8_t testBuffer[ MQTT_TEST_BUFFER_LENGTH ]; MQTTPropBuilder_t propBuilder = { 0 }; MQTTStatus_t status; - uint32_t currentIndex = 0; + size_t currentIndex = 0; uint8_t * pIndex = testBuffer; propBuilder.pBuffer = testBuffer; @@ -7473,7 +7658,7 @@ void test_MQTT_SkipNextProperty_SubscriptionId_FourBytes( void ) uint8_t testBuffer[ MQTT_TEST_BUFFER_LENGTH ]; MQTTPropBuilder_t propBuilder = { 0 }; MQTTStatus_t status; - uint32_t currentIndex = 0; + size_t currentIndex = 0; uint8_t * pIndex = testBuffer; propBuilder.pBuffer = testBuffer; @@ -7498,7 +7683,7 @@ void test_MQTT_SkipNextProperty_SubscriptionId_InsufficientBuffer( void ) uint8_t testBuffer[ MQTT_TEST_BUFFER_LENGTH ]; MQTTPropBuilder_t propBuilder = { 0 }; MQTTStatus_t status; - uint32_t currentIndex = 0; + size_t currentIndex = 0; propBuilder.pBuffer = testBuffer; propBuilder.bufferLength = MQTT_TEST_BUFFER_LENGTH; @@ -7521,7 +7706,7 @@ void test_MQTT_SkipNextProperty_SubscriptionId_InvalidEncoding( void ) uint8_t testBuffer[ MQTT_TEST_BUFFER_LENGTH ]; MQTTPropBuilder_t propBuilder = { 0 }; MQTTStatus_t status; - uint32_t currentIndex = 0; + size_t currentIndex = 0; uint8_t * pIndex = testBuffer; propBuilder.pBuffer = testBuffer; @@ -7553,7 +7738,7 @@ void test_MQTT_SkipNextProperty_MultipleProperties( void ) uint8_t testBuffer[ MQTT_TEST_BUFFER_LENGTH ]; MQTTPropBuilder_t propBuilder = { 0 }; MQTTStatus_t status; - uint32_t currentIndex = 0; + size_t currentIndex = 0; uint8_t * pIndex = testBuffer; propBuilder.pBuffer = testBuffer; @@ -7605,7 +7790,7 @@ void test_MQTT_SkipNextProperty_AtBufferBoundary( void ) uint8_t testBuffer[ MQTT_TEST_BUFFER_LENGTH ]; MQTTPropBuilder_t propBuilder = { 0 }; MQTTStatus_t status; - uint32_t currentIndex = 0; + size_t currentIndex = 0; uint8_t * pIndex = testBuffer; propBuilder.pBuffer = testBuffer; @@ -7634,7 +7819,7 @@ void test_MQTT_SkipNextProperty_ZeroLengthString( void ) uint8_t testBuffer[ MQTT_TEST_BUFFER_LENGTH ]; MQTTPropBuilder_t propBuilder = { 0 }; MQTTStatus_t status; - uint32_t currentIndex = 0; + size_t currentIndex = 0; uint8_t * pIndex = testBuffer; propBuilder.pBuffer = testBuffer; @@ -7660,7 +7845,7 @@ void test_MQTT_SkipNextProperty_UserProperty_ZeroLength( void ) uint8_t testBuffer[ MQTT_TEST_BUFFER_LENGTH ]; MQTTPropBuilder_t propBuilder = { 0 }; MQTTStatus_t status; - uint32_t currentIndex = 0; + size_t currentIndex = 0; uint8_t * pIndex = testBuffer; propBuilder.pBuffer = testBuffer; @@ -7688,7 +7873,7 @@ void test_MQTT_SkipNextProperty_SubscriptionId_Zero( void ) uint8_t testBuffer[ MQTT_TEST_BUFFER_LENGTH ]; MQTTPropBuilder_t propBuilder = { 0 }; MQTTStatus_t status; - uint32_t currentIndex = 0; + size_t currentIndex = 0; uint8_t * pIndex = testBuffer; propBuilder.pBuffer = testBuffer; @@ -7714,7 +7899,7 @@ void test_MQTT_SkipNextProperty_MaxUtf8Length( void ) uint8_t testBuffer[ MQTT_TEST_BUFFER_LENGTH ]; MQTTPropBuilder_t propBuilder = { 0 }; MQTTStatus_t status; - uint32_t currentIndex = 0; + size_t currentIndex = 0; uint8_t * pIndex = testBuffer; propBuilder.pBuffer = testBuffer; @@ -7742,7 +7927,7 @@ void test_MQTT_SkipNextProperty_AllPropertyTypes( void ) uint8_t testBuffer[ MQTT_TEST_BUFFER_LENGTH ]; MQTTPropBuilder_t propBuilder = { 0 }; MQTTStatus_t status; - uint32_t currentIndex = 0; + size_t currentIndex = 0; uint8_t * pIndex = testBuffer; uint32_t expectedIndex; diff --git a/test/unit-test/core_mqtt_utest.c b/test/unit-test/core_mqtt_utest.c index f8e37b91..5efbc6b0 100644 --- a/test/unit-test/core_mqtt_utest.c +++ b/test/unit-test/core_mqtt_utest.c @@ -601,7 +601,7 @@ static MQTTStatus_t MQTT_SerializeAck_SuccessAndSetDisconnPending( const MQTTFix static uint8_t * MQTTV5_SerializeAckFixed_cb( uint8_t * pIndex, uint8_t packetType, uint16_t packetId, - size_t remainingLength, + uint32_t remainingLength, MQTTSuccessFailReasonCode_t reasonCode, int numcallbacks ) { @@ -663,7 +663,7 @@ MQTTStatus_t MQTT_SerializeAck_StubSuccess( const MQTTFixedBuffer_t * pFixedBuff static uint8_t * MQTTV5_SerializeDisconnectFixed_cb( uint8_t * pIndex, MQTTSuccessFailReasonCode_t * pReasonCode, - size_t remainingLength, + uint32_t remainingLength, int numcallbacks ) { ( void ) pIndex; @@ -730,8 +730,8 @@ static int32_t transportWritevSuccess( NetworkContext_t * pNetworkContext, } static MQTTStatus_t MQTT_GetDisconnectPacketSize_ExpectReasonMalformed( const MQTTPropBuilder_t * pDisconnectProperties, - size_t * pRemainingLength, - size_t * pPacketSize, + uint32_t * pRemainingLength, + uint32_t * pPacketSize, uint32_t maxPacketSize, MQTTSuccessFailReasonCode_t * pReasonCode, int numcallbacks ) @@ -750,7 +750,7 @@ static MQTTStatus_t MQTT_GetDisconnectPacketSize_ExpectReasonMalformed( const MQ static uint8_t * serializeDisconnectFixed_cb_OneByte( uint8_t * pIndex, MQTTSuccessFailReasonCode_t * pReasonCode, - size_t remainingLength, + uint32_t remainingLength, int numcallbacks ) { ( void ) pReasonCode; @@ -1515,7 +1515,7 @@ static void expectProcessLoopCalls( MQTTContext_t * const pContext, { MQTTStatus_t mqttStatus = MQTTSuccess; MQTTPacketInfo_t incomingPacket = { 0 }; - size_t pingreqSize = MQTT_PACKET_PINGREQ_SIZE; + uint32_t pingreqSize = MQTT_PACKET_PINGREQ_SIZE; bool expectMoreCalls = true; /* Copy values passed in the parameter struct. */ MQTTStatus_t deserializeStatus = pExpectParams->deserializeStatus; @@ -4689,7 +4689,7 @@ void test_MQTT_Disconnect_already_disconnected( void ) MQTTStatus_t status; TransportInterface_t transport = { 0 }; MQTTFixedBuffer_t networkBuffer = { 0 }; - size_t disconnectSize = 2; + uint32_t disconnectSize = 2; setupTransportInterface( &transport ); setupNetworkBuffer( &networkBuffer ); @@ -4782,7 +4782,7 @@ void test_MQTT_Disconnect2( void ) NetworkContext_t networkContext = { 0 }; TransportInterface_t transport = { 0 }; MQTTFixedBuffer_t networkBuffer = { 0 }; - size_t disconnectSize = 2; + uint32_t disconnectSize = 2; setupTransportInterface( &transport ); setupNetworkBuffer( &networkBuffer ); @@ -4854,7 +4854,7 @@ void test_MQTT_Disconnect4( void ) NetworkContext_t networkContext = { 0 }; TransportInterface_t transport = { 0 }; MQTTFixedBuffer_t networkBuffer = { 0 }; - size_t disconnectSize = 2; + uint32_t disconnectSize = 2; /* Fill the buffer with garbage data. */ memset( mqttBuffer, 0xAB, MQTT_TEST_BUFFER_LENGTH ); @@ -4908,7 +4908,7 @@ void test_MQTT_Disconnect4_status_disconnect_pending( void ) NetworkContext_t networkContext = { 0 }; TransportInterface_t transport = { 0 }; MQTTFixedBuffer_t networkBuffer = { 0 }; - size_t disconnectSize = 2; + uint32_t disconnectSize = 2; /* Fill the buffer with garbage data. */ memset( mqttBuffer, 0xAB, MQTT_TEST_BUFFER_LENGTH ); @@ -5146,7 +5146,7 @@ void test_MQTT_ProcessLoop_HandleKeepAlive1( void ) TransportInterface_t transport = { 0 }; MQTTFixedBuffer_t networkBuffer = { 0 }; MQTTStatus_t mqttStatus; - size_t pingreqSize = MQTT_PACKET_PINGREQ_SIZE; + uint32_t pingreqSize = MQTT_PACKET_PINGREQ_SIZE; setupTransportInterface( &transport ); transport.recv = transportRecvNoData; @@ -6538,7 +6538,7 @@ void test_MQTT_ProcessLoop_handleKeepAlive_Error_Paths3( void ) context.waitingForPingResp = false; /* Set expected return values in the loop. */ resetProcessLoopParams( &expectParams ); - size_t packetSize = MQTT_PACKET_PINGREQ_SIZE; + uint32_t packetSize = MQTT_PACKET_PINGREQ_SIZE; MQTT_GetPingreqPacketSize_ExpectAnyArgsAndReturn( MQTTSuccess ); MQTT_GetPingreqPacketSize_ReturnThruPtr_pPacketSize( &packetSize ); MQTT_SerializePingreq_ExpectAnyArgsAndReturn( MQTTSuccess ); @@ -6559,7 +6559,7 @@ void test_MQTT_ProcessLoop_handleKeepAlive_Error_Paths4( void ) TransportInterface_t transport = { 0 }; MQTTFixedBuffer_t networkBuffer = { 0 }; ProcessLoopReturns_t expectParams = { 0 }; - size_t packetSize = MQTT_PACKET_PINGREQ_SIZE; + uint32_t packetSize = MQTT_PACKET_PINGREQ_SIZE; setupTransportInterface( &transport ); transport.recv = transportRecvNoData; @@ -7668,7 +7668,7 @@ static void setupSubscriptionInfo( MQTTSubscribeInfo_t * pSubscribeInfo ) } -static uint8_t * MQTTV5_SerializeSubscribedHeader_cb( size_t remainingLength, +static uint8_t * MQTTV5_SerializeSubscribedHeader_cb( uint32_t remainingLength, uint8_t * pIndex, uint16_t packetId, int numcallbacks ) @@ -7681,7 +7681,7 @@ static uint8_t * MQTTV5_SerializeSubscribedHeader_cb( size_t remainingLength, return pIndex; } -static uint8_t * MQTT_SerializeSubscribedHeader_cb2( size_t remainingLength, +static uint8_t * MQTT_SerializeSubscribedHeader_cb2( uint32_t remainingLength, uint8_t * pIndex, uint16_t packetId, int numcallbacks ) @@ -7696,7 +7696,7 @@ static uint8_t * MQTT_SerializeSubscribedHeader_cb2( size_t remainingLength, return pIndex + SubscribeHeaderLength; } -static uint8_t * MQTT_SerializeUnsubscribedHeader_cb2( size_t remainingLength, +static uint8_t * MQTT_SerializeUnsubscribedHeader_cb2( uint32_t remainingLength, uint8_t * pIndex, uint16_t packetId, int numcallbacks ) @@ -7883,8 +7883,8 @@ void test_MQTTV5_Subscribe_happy_path( void ) MQTTFixedBuffer_t networkBuffer = { 0 }; MQTTSubscribeInfo_t subscribeInfo = { 0 }; - size_t remainingLength = MQTT_SAMPLE_REMAINING_LENGTH; - size_t packetSize = MQTT_SAMPLE_REMAINING_LENGTH; + uint32_t remainingLength = MQTT_SAMPLE_REMAINING_LENGTH; + uint32_t packetSize = MQTT_SAMPLE_REMAINING_LENGTH; MQTTPubAckInfo_t incomingRecords = { 0 }; MQTTPubAckInfo_t outgoingRecords = { 0 }; @@ -7953,8 +7953,8 @@ void test_MQTT_Subscribe_happy_path_not_connected( void ) TransportInterface_t transport = { 0 }; MQTTFixedBuffer_t networkBuffer = { 0 }; MQTTSubscribeInfo_t subscribeInfo = { 0 }; - size_t remainingLength = MQTT_SAMPLE_REMAINING_LENGTH; - size_t packetSize = MQTT_SAMPLE_REMAINING_LENGTH; + uint32_t remainingLength = MQTT_SAMPLE_REMAINING_LENGTH; + uint32_t packetSize = MQTT_SAMPLE_REMAINING_LENGTH; MQTTPubAckInfo_t incomingRecords = { 0 }; MQTTPubAckInfo_t outgoingRecords = { 0 }; uint8_t ackPropsBuf[ 500 ]; @@ -8004,8 +8004,8 @@ void test_MQTTV5_Subscribe_happy_path1( void ) TransportInterface_t transport = { 0 }; MQTTFixedBuffer_t networkBuffer = { 0 }; MQTTSubscribeInfo_t subscribeInfo[ 2 ]; - size_t remainingLength = MQTT_SAMPLE_REMAINING_LENGTH; - size_t packetSize = MQTT_SAMPLE_REMAINING_LENGTH; + uint32_t remainingLength = MQTT_SAMPLE_REMAINING_LENGTH; + uint32_t packetSize = MQTT_SAMPLE_REMAINING_LENGTH; MQTTPubAckInfo_t incomingRecords = { 0 }; MQTTPubAckInfo_t outgoingRecords = { 0 }; @@ -8083,8 +8083,8 @@ void test_MQTTV5_Subscribe_happy_path2( void ) TransportInterface_t transport = { 0 }; MQTTFixedBuffer_t networkBuffer = { 0 }; MQTTSubscribeInfo_t subscribeInfo = { 0 }; - size_t remainingLength = MQTT_SAMPLE_REMAINING_LENGTH; - size_t packetSize = MQTT_SAMPLE_REMAINING_LENGTH; + uint32_t remainingLength = MQTT_SAMPLE_REMAINING_LENGTH; + uint32_t packetSize = MQTT_SAMPLE_REMAINING_LENGTH; MQTTPubAckInfo_t incomingRecords = { 0 }; MQTTPubAckInfo_t outgoingRecords = { 0 }; uint8_t ackPropsBuf[ 500 ]; @@ -8131,8 +8131,8 @@ void test_MQTT_Subscribe_MultipleSubscriptions( void ) TransportInterface_t transport = { 0 }; MQTTFixedBuffer_t networkBuffer = { 0 }; MQTTSubscribeInfo_t subscribeInfo[ 5 ]; - size_t remainingLength = MQTT_SAMPLE_REMAINING_LENGTH; - size_t packetSize = MQTT_SAMPLE_REMAINING_LENGTH; + uint32_t remainingLength = MQTT_SAMPLE_REMAINING_LENGTH; + uint32_t packetSize = MQTT_SAMPLE_REMAINING_LENGTH; MQTTPubAckInfo_t incomingRecords = { 0 }; MQTTPubAckInfo_t outgoingRecords = { 0 }; @@ -8204,8 +8204,8 @@ void test_MQTTV5_Subscribe_happy_path3( void ) TransportInterface_t transport = { 0 }; MQTTFixedBuffer_t networkBuffer = { 0 }; MQTTSubscribeInfo_t subscribeInfo = { 0 }; - size_t remainingLength = MQTT_SAMPLE_REMAINING_LENGTH; - size_t packetSize = MQTT_SAMPLE_REMAINING_LENGTH; + uint32_t remainingLength = MQTT_SAMPLE_REMAINING_LENGTH; + uint32_t packetSize = MQTT_SAMPLE_REMAINING_LENGTH; MQTTPubAckInfo_t incomingRecords = { 0 }; MQTTPubAckInfo_t outgoingRecords = { 0 }; @@ -8258,8 +8258,8 @@ void test_MQTT_Subscribe_error_paths1( void ) TransportInterface_t transport = { 0 }; MQTTFixedBuffer_t networkBuffer = { 0 }; MQTTSubscribeInfo_t subscribeInfo = { 0 }; - size_t remainingLength = MQTT_SAMPLE_REMAINING_LENGTH; - size_t packetSize = MQTT_SAMPLE_REMAINING_LENGTH; + uint32_t remainingLength = MQTT_SAMPLE_REMAINING_LENGTH; + uint32_t packetSize = MQTT_SAMPLE_REMAINING_LENGTH; /* Verify that an error is propagated when transport interface returns an error. */ setupNetworkBuffer( &networkBuffer ); @@ -8298,8 +8298,8 @@ void test_MQTT_Unsubscribe_error_paths1( void ) TransportInterface_t transport = { 0 }; MQTTFixedBuffer_t networkBuffer = { 0 }; MQTTSubscribeInfo_t subscribeInfo = { 0 }; - size_t remainingLength = MQTT_SAMPLE_REMAINING_LENGTH; - size_t packetSize = MQTT_SAMPLE_REMAINING_LENGTH; + uint32_t remainingLength = MQTT_SAMPLE_REMAINING_LENGTH; + uint32_t packetSize = MQTT_SAMPLE_REMAINING_LENGTH; /* Verify that an error is propagated when transport interface returns an error. */ setupNetworkBuffer( &networkBuffer ); @@ -8338,8 +8338,8 @@ void test_MQTT_Subscribe_error_paths_timerOverflowCheck( void ) TransportInterface_t transport = { 0 }; MQTTFixedBuffer_t networkBuffer = { 0 }; MQTTSubscribeInfo_t subscribeInfo = { 0 }; - size_t remainingLength = MQTT_SAMPLE_REMAINING_LENGTH; - size_t packetSize = MQTT_SAMPLE_REMAINING_LENGTH; + uint32_t remainingLength = MQTT_SAMPLE_REMAINING_LENGTH; + uint32_t packetSize = MQTT_SAMPLE_REMAINING_LENGTH; globalEntryTime = UINT32_MAX - 2U; @@ -8385,8 +8385,8 @@ void test_MQTT_Subscribe_error_paths_timerOverflowCheck1( void ) TransportInterface_t transport = { 0 }; MQTTFixedBuffer_t networkBuffer = { 0 }; MQTTSubscribeInfo_t subscribeInfo = { 0 }; - size_t remainingLength = MQTT_SAMPLE_REMAINING_LENGTH; - size_t packetSize = MQTT_SAMPLE_REMAINING_LENGTH; + uint32_t remainingLength = MQTT_SAMPLE_REMAINING_LENGTH; + uint32_t packetSize = MQTT_SAMPLE_REMAINING_LENGTH; globalEntryTime = UINT32_MAX - MQTT_SEND_TIMEOUT_MS + 1; @@ -8432,8 +8432,8 @@ void test_MQTT_Subscribe_error_paths2( void ) TransportInterface_t transport = { 0 }; MQTTFixedBuffer_t networkBuffer = { 0 }; MQTTSubscribeInfo_t subscribeInfo = { 0 }; - size_t remainingLength = MQTT_SAMPLE_REMAINING_LENGTH; - size_t packetSize = MQTT_SAMPLE_REMAINING_LENGTH; + uint32_t remainingLength = MQTT_SAMPLE_REMAINING_LENGTH; + uint32_t packetSize = MQTT_SAMPLE_REMAINING_LENGTH; /* Verify that an error is propagated when transport interface returns an error. */ setupNetworkBuffer( &networkBuffer ); @@ -8472,8 +8472,8 @@ void test_MQTT_Subscribe_error_paths_with_transport_failure( void ) TransportInterface_t transport = { 0 }; MQTTFixedBuffer_t networkBuffer = { 0 }; MQTTSubscribeInfo_t subscribeInfo = { 0 }; - size_t remainingLength = MQTT_SAMPLE_REMAINING_LENGTH; - size_t packetSize = MQTT_SAMPLE_REMAINING_LENGTH; + uint32_t remainingLength = MQTT_SAMPLE_REMAINING_LENGTH; + uint32_t packetSize = MQTT_SAMPLE_REMAINING_LENGTH; /* Verify that an error is propagated when transport interface returns an error. */ setupNetworkBuffer( &networkBuffer ); @@ -8509,8 +8509,8 @@ void test_MQTTV5_shared_subscriptions( void ) MQTTSubscribeInfo_t subscribeInfo = { 0 }; MQTTPubAckInfo_t incomingRecords = { 0 }; MQTTPubAckInfo_t outgoingRecords = { 0 }; - size_t remainingLength = MQTT_SAMPLE_REMAINING_LENGTH; - size_t packetSize = MQTT_SAMPLE_REMAINING_LENGTH; + uint32_t remainingLength = MQTT_SAMPLE_REMAINING_LENGTH; + uint32_t packetSize = MQTT_SAMPLE_REMAINING_LENGTH; uint8_t ackPropsBuf[ 500 ]; size_t ackPropsBufLength = sizeof( ackPropsBuf ); @@ -8638,7 +8638,7 @@ void test_MQTT_Unsubscribe_invalid_params( void ) } -static uint8_t * MQTTV5_SerializeUnsubscribeHeader_cb( size_t remainingLength, +static uint8_t * MQTTV5_SerializeUnsubscribeHeader_cb( uint32_t remainingLength, uint8_t * pIndex, uint16_t packetId, int numcallbacks ) @@ -8662,8 +8662,8 @@ void test_MQTT_Unsubscribe_happy_path( void ) TransportInterface_t transport = { 0 }; MQTTFixedBuffer_t networkBuffer = { 0 }; MQTTSubscribeInfo_t subscribeInfo = { 0 }; - size_t remainingLength = MQTT_SAMPLE_REMAINING_LENGTH; - size_t packetSize = MQTT_SAMPLE_REMAINING_LENGTH; + uint32_t remainingLength = MQTT_SAMPLE_REMAINING_LENGTH; + uint32_t packetSize = MQTT_SAMPLE_REMAINING_LENGTH; setupTransportInterface( &transport ); setupNetworkBuffer( &networkBuffer ); @@ -8723,8 +8723,8 @@ void test_MQTT_Unsubscribe_MultipleSubscriptions( void ) TransportInterface_t transport = { 0 }; MQTTFixedBuffer_t networkBuffer = { 0 }; MQTTSubscribeInfo_t subscribeInfo[ 5 ]; - size_t remainingLength = MQTT_SAMPLE_REMAINING_LENGTH; - size_t packetSize = MQTT_SAMPLE_REMAINING_LENGTH; + uint32_t remainingLength = MQTT_SAMPLE_REMAINING_LENGTH; + uint32_t packetSize = MQTT_SAMPLE_REMAINING_LENGTH; MQTTPubAckInfo_t incomingRecords = { 0 }; MQTTPubAckInfo_t outgoingRecords = { 0 }; uint8_t buf[ 100 ]; @@ -8785,8 +8785,8 @@ void test_MQTT_Unsubscribe_happy_path_withUP( void ) TransportInterface_t transport = { 0 }; MQTTFixedBuffer_t networkBuffer = { 0 }; MQTTSubscribeInfo_t subscribeInfo = { 0 }; - size_t remainingLength = MQTT_SAMPLE_REMAINING_LENGTH; - size_t packetSize = MQTT_SAMPLE_REMAINING_LENGTH; + uint32_t remainingLength = MQTT_SAMPLE_REMAINING_LENGTH; + uint32_t packetSize = MQTT_SAMPLE_REMAINING_LENGTH; setupTransportInterface( &transport ); setupNetworkBuffer( &networkBuffer ); @@ -8816,8 +8816,8 @@ void test_MQTTV5_Unsubscribe_happy_path( void ) MQTTFixedBuffer_t networkBuffer = { 0 }; MQTTSubscribeInfo_t subscribeInfo = { 0 }; - size_t remainingLength = MQTT_SAMPLE_REMAINING_LENGTH; - size_t packetSize = MQTT_SAMPLE_REMAINING_LENGTH; + uint32_t remainingLength = MQTT_SAMPLE_REMAINING_LENGTH; + uint32_t packetSize = MQTT_SAMPLE_REMAINING_LENGTH; MQTTPubAckInfo_t incomingRecords = { 0 }; MQTTPubAckInfo_t outgoingRecords = { 0 }; @@ -8874,8 +8874,8 @@ void test_MQTT_Unsubscribe_not_connected( void ) TransportInterface_t transport = { 0 }; MQTTFixedBuffer_t networkBuffer = { 0 }; MQTTSubscribeInfo_t subscribeInfo = { 0 }; - size_t remainingLength = MQTT_SAMPLE_REMAINING_LENGTH; - size_t packetSize = MQTT_SAMPLE_REMAINING_LENGTH; + uint32_t remainingLength = MQTT_SAMPLE_REMAINING_LENGTH; + uint32_t packetSize = MQTT_SAMPLE_REMAINING_LENGTH; setupTransportInterface( &transport ); setupNetworkBuffer( &networkBuffer ); @@ -8930,7 +8930,7 @@ void test_MQTT_Ping_happy_path( void ) MQTTContext_t context = { 0 }; TransportInterface_t transport = { 0 }; MQTTFixedBuffer_t networkBuffer = { 0 }; - size_t pingreqSize = MQTT_PACKET_PINGREQ_SIZE; + uint32_t pingreqSize = MQTT_PACKET_PINGREQ_SIZE; setupTransportInterface( &transport ); setupNetworkBuffer( &networkBuffer ); @@ -8962,7 +8962,7 @@ void test_MQTT_Ping_not_connected( void ) MQTTContext_t context = { 0 }; TransportInterface_t transport = { 0 }; MQTTFixedBuffer_t networkBuffer = { 0 }; - size_t pingreqSize = MQTT_PACKET_PINGREQ_SIZE; + uint32_t pingreqSize = MQTT_PACKET_PINGREQ_SIZE; setupTransportInterface( &transport ); setupNetworkBuffer( &networkBuffer ); @@ -9004,7 +9004,7 @@ void test_MQTT_Ping_error_path( void ) MQTTContext_t context = { 0 }; TransportInterface_t transport = { 0 }; MQTTFixedBuffer_t networkBuffer = { 0 }; - size_t pingreqSize = MQTT_PACKET_PINGREQ_SIZE; + uint32_t pingreqSize = MQTT_PACKET_PINGREQ_SIZE; setupTransportInterface( &transport ); setupNetworkBuffer( &networkBuffer );