Skip to content
Closed
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
4 changes: 2 additions & 2 deletions source/core_mqtt_serializer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1706,9 +1706,9 @@ MQTTStatus_t MQTT_GetConnectPacketSize( const MQTTConnectInfo_t * pConnectInfo,
( void * ) pPacketSize ) );
status = MQTTBadParameter;
}
else if( ( pConnectInfo->clientIdentifierLength == 0U ) || ( pConnectInfo->pClientIdentifier == NULL ) )
else if( ( ( pConnectInfo->clientIdentifierLength == 0U ) || ( pConnectInfo->pClientIdentifier == NULL ) ) && ( pConnectInfo->cleanSession == false ) )
{
LogError( ( "Mqtt_GetConnectPacketSize() client identifier must be set." ) );
LogError( ( "Zero-length client identifier requires cleanSession=true per MQTT 3.1.1." ) );
status = MQTTBadParameter;
}
Comment on lines 1712 to 1713
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also add this below check since on line connectPacketSize += pConnectInfo->clientIdentifierLength + sizeof( uint16_t ); we are updating the length based only on the length provided by the user without checking whether the value itself is NULL. That will cause an issue.

@Ryan-CW-Code what do you think? I am open to combining the checks too. But I am currently out of office and can help once I am back.

Suggested change
status = MQTTBadParameter;
}
status = MQTTBadParameter;
}
else if( ( pConnectInfo->clientIdentifierLength == 0U ) ^ ( pConnectInfo->pClientIdentifier == NULL ) )
{
LogError( ( "Client ID length and value mismatch." ) );
status = MQTTBadParameter;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we pulled this check before the check on 1709 we could reduce that check too since the XOR implies that if the length is 0 that the value must be NULL.

Not sure I'm sold on this simplification as the code will no longer so obviously equate NULL to 0 length. I like this suggestion.

else if( ( pWillInfo != NULL ) && ( pWillInfo->payloadLength > ( size_t ) UINT16_MAX ) )
Expand Down
Loading