Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check for 0 packet ID for subacks #159

Merged
merged 3 commits into from
Jul 8, 2021
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
## Commits to `main`

### Updates
- [#163](https://github.com/FreeRTOS/coreMQTT/pull/163) Fix bug to check for ping responses within `MQTT_PINGRESP_TIMEOUT_MS` instead of the entire keep alive interval
- [#163](https://github.com/FreeRTOS/coreMQTT/pull/163) Fix bug to check for ping responses within `MQTT_PINGRESP_TIMEOUT_MS` instead of the entire keep alive interval.
- [#159](https://github.com/FreeRTOS/coreMQTT/pull/159) Add more checks for malformed packets when deserializing acknowledgments.

## v1.1.1 (February 2021)

Expand Down
Empty file modified LICENSE
100755 → 100644
Empty file.
6 changes: 3 additions & 3 deletions lexicon.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ cleansession
clientidentifierlength
cmock
colspan
copydoc
com
cond
config
Expand All @@ -42,6 +41,7 @@ connack
connectinfo
connectpacketsize
const
copydoc
coremqtt
csdk
css
Expand All @@ -52,11 +52,11 @@ defragmenting
deserialization
deserializationresult
deserialize
deserializers
deserializeack
deserialized
deserializepublish
deserializer
deserializers
deserializestatus
deserializing
didn
Expand Down Expand Up @@ -126,10 +126,10 @@ logwarn
lsb
lwt
mainpage
mdash
malloc
managekeepalive
matchtopic
mdash
memcpy
memset
metadata
Expand Down
11 changes: 9 additions & 2 deletions source/core_mqtt_serializer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1164,8 +1164,15 @@ static MQTTStatus_t deserializeSuback( const MQTTPacketInfo_t * pSuback,
LogDebug( ( "Packet identifier %hu.",
( unsigned short ) *pPacketIdentifier ) );

status = readSubackStatus( remainingLength - sizeof( uint16_t ),
pVariableHeader + sizeof( uint16_t ) );
if( *pPacketIdentifier == 0U )
Copy link
Contributor

Choose a reason for hiding this comment

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

Should the MQTT_PACKET_ID_INVALID macro be moved the serializer API?https://github.com/FreeRTOS/coreMQTT/blob/main/source/include/core_mqtt.h#L55-L61

Suggested change
if( *pPacketIdentifier == 0U )
if( *pPacketIdentifier == MQTT_PACKET_ID_INVALID )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh wow, I forgot about this. Possibly, but doing that is a larger change than what this PR was focused on.

{
status = MQTTBadResponse;
}
else
{
status = readSubackStatus( remainingLength - sizeof( uint16_t ),
pVariableHeader + sizeof( uint16_t ) );
}
}

return status;
Expand Down
8 changes: 8 additions & 0 deletions test/unit-test/core_mqtt_serializer_utest.c
Original file line number Diff line number Diff line change
Expand Up @@ -1480,6 +1480,14 @@ void test_MQTT_DeserializeAck_suback( void )
status = MQTT_DeserializeAck( &mqttPacketInfo, &packetIdentifier, &sessionPresent );
TEST_ASSERT_EQUAL_INT( MQTTBadResponse, status );

/* Invalid packet ID. */
buffer[ 0 ] = 0;
buffer[ 1 ] = 0;
mqttPacketInfo.remainingLength = 3;
buffer[ 2 ] = 0;
status = MQTT_DeserializeAck( &mqttPacketInfo, &packetIdentifier, &sessionPresent );
TEST_ASSERT_EQUAL_INT( MQTTBadResponse, status );

/* Set packet identifier. */
buffer[ 0 ] = 0;
buffer[ 1 ] = 1;
Expand Down