Skip to content

Commit 38c200e

Browse files
Fix issues pointed out in PR comments
1 parent ee55c84 commit 38c200e

File tree

4 files changed

+16
-13
lines changed

4 files changed

+16
-13
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ jobs:
8383
uses: FreeRTOS/CI-CD-Github-Actions/coverage-cop@main
8484
with:
8585
coverage-file: ./build/coverage.info
86-
line-coverage-min: 94
86+
branch-coverage-min: 94
8787

8888
complexity:
8989
runs-on: ubuntu-latest

source/core_mqtt.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2359,10 +2359,8 @@ static MQTTStatus_t receiveSingleIteration( MQTTContext_t * pContext,
23592359
/* If the MQTT Packet size is bigger than the buffer itself. */
23602360
else if( totalMQTTPacketLength > pContext->networkBuffer.size )
23612361
{
2362-
LogError( ( "Incoming packet size is bigger than MQTT buffer size. "
2363-
"coreMQTT cannot handle such packets as 'dropping' packets is "
2364-
"not allowed by the MQTT spec. Application MUST provide a bigger "
2365-
"buffer to handle such packets." ) );
2362+
LogError( ( "Incoming packet size is bigger than MQTT buffer size. Total packet length %" PRIu32,
2363+
totalMQTTPacketLength ) );
23662364
status = MQTTRecvFailed;
23672365
}
23682366
/* If the total packet is of more length than the bytes we have available. */
@@ -4314,7 +4312,7 @@ MQTTStatus_t MQTT_Connect( MQTTContext_t * pContext,
43144312
if( pBackupPropBuilder != NULL )
43154313
{
43164314
bool isRequestProblemInfoSet;
4317-
uint32_t packetMaxSize;
4315+
uint32_t packetMaxSize = UINT32_MAX;
43184316
status = MQTT_ValidateConnectProperties( pBackupPropBuilder,
43194317
&isRequestProblemInfoSet,
43204318
&packetMaxSize );
@@ -4343,11 +4341,9 @@ MQTTStatus_t MQTT_Connect( MQTTContext_t * pContext,
43434341

43444342
assert( !CHECK_SIZE_T_OVERFLOWS_32BIT( pContext->networkBuffer.size ) );
43454343

4346-
LogWarn( ( "Application has not set any properties. coreMQTT will add a property to "
4347-
"set the maximum packet size received from the server. This prevents the case "
4348-
"when the incoming packet is greater than the buffer size. In such case, the "
4349-
"packet cannot be dropped by the library neither can it be processed. Setting "
4350-
"the value of the property to: %" PRIu32, ( uint32_t ) pContext->networkBuffer.size ) );
4344+
LogInfo( ( "Application has not set any properties. Adding a property to set the maximum "
4345+
"packet size received from the server for the client to be %" PRIu32 ".",
4346+
( uint32_t ) pContext->networkBuffer.size ) );
43514347
status = MQTTPropAdd_MaxPacketSize( pBackupPropBuilder,
43524348
pContext->networkBuffer.size,
43534349
NULL );

source/include/core_mqtt.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,13 @@ MQTTStatus_t MQTT_CheckConnectStatus( const MQTTContext_t * pContext );
731731
* #MQTTEventCallbackFailed if the user defined callback fails.<br>
732732
* #MQTTSuccess otherwise.<br>
733733
*
734+
* @note If no properties are provided (by setting @p pPropertyBuilder to NULL), coreMQTT
735+
* will add a property to the connect packet to limit the maximum packet size that the
736+
* broker can send to be equal to the application provided buffer to the #MQTT_Init API.
737+
* This prevents the case when the packet is bigger than the buffer at which point,
738+
* coreMQTT cannot handle the packet, neither can it drop it as MQTT protocol doesn't
739+
* allow it.
740+
*
734741
* @note This API may spend more time than provided in the timeoutMS parameters in
735742
* certain conditions as listed below:
736743
*

test/unit-test/core_mqtt_utest.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9640,7 +9640,7 @@ void test_MQTT_MatchTopic_topicNameLength_Overflow( void )
96409640
size_t topicFilterlen = 14;
96419641
bool matchResult = false;
96429642

9643-
/* NULL topic name. */
9643+
/* Topic name length more than maximum allowed length. */
96449644
TEST_ASSERT_EQUAL( MQTTBadParameter, MQTT_MatchTopic( pTopicName,
96459645
topicNameLength,
96469646
pTopicFilter,
@@ -9656,7 +9656,7 @@ void test_MQTT_MatchTopic_topicFilterLength_Overflow( void )
96569656
size_t topicFilterlen = 65536;
96579657
bool matchResult = false;
96589658

9659-
/* NULL topic name. */
9659+
/* Topic filter length more than maximum allowed length. */
96609660
TEST_ASSERT_EQUAL( MQTTBadParameter, MQTT_MatchTopic( pTopicName,
96619661
topicNameLength,
96629662
pTopicFilter,

0 commit comments

Comments
 (0)