Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions docs/doxygen/include/size_table.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</tr>
<tr>
<td>core_mqtt.c</td>
<td><center>7.5K</center></td>
<td><center>7.6K</center></td>
<td><center>6.7K</center></td>
</tr>
<tr>
Expand All @@ -19,8 +19,8 @@
</tr>
<tr>
<td>core_mqtt_serializer.c</td>
<td><center>8.8K</center></td>
<td><center>7.2K</center></td>
<td><center>9.1K</center></td>
<td><center>7.3K</center></td>
</tr>
<tr>
<td>core_mqtt_serializer_private.c</td>
Expand All @@ -29,8 +29,8 @@
</tr>
<tr>
<td>core_mqtt_prop_serializer.c</td>
<td><center>1.3K</center></td>
<td><center>1.1K</center></td>
<td><center>1.4K</center></td>
<td><center>1.2K</center></td>
</tr>
<tr>
<td>core_mqtt_prop_deserializer.c</td>
Expand All @@ -39,7 +39,7 @@
</tr>
<tr>
<td><b>Total estimates</b></td>
<td><b><center>21.4K</center></b></td>
<td><b><center>18.0K</center></b></td>
<td><b><center>21.9K</center></b></td>
<td><b><center>18.2K</center></b></td>
</tr>
</table>
84 changes: 60 additions & 24 deletions source/core_mqtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down Expand Up @@ -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 );

/**
Expand All @@ -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 );

/**
Expand Down Expand Up @@ -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 );

/**
Expand Down Expand Up @@ -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 );

/**
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -3057,15 +3061,15 @@ 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 )
{
MQTTStatus_t status = MQTTSuccess;
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 ];
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 "
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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. */
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Loading
Loading