Add unit tests for MQTTPropAdd buffer and packet size limit error paths#377
Open
guclumhg wants to merge 1 commit into
Open
Add unit tests for MQTTPropAdd buffer and packet size limit error paths#377guclumhg wants to merge 1 commit into
guclumhg wants to merge 1 commit into
Conversation
Cover previously untested error branches in core_mqtt_prop_serializer.c: - Buffer-full-at-currentIndex paths in the addPropUint8/16/32 helpers and MQTTPropAdd_SubscriptionId. - Maximum MQTT remaining length (268,435,455) checks in MQTTPropAdd_SubscriptionId. - 16-bit key/value length validation in MQTTPropAdd_UserProp. Raises the file to 100% line coverage and 180/182 branches. The two remaining branch directions in addPropUtf8 are unreachable in assert-enabled builds.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds six unit tests covering previously untested error paths in
core_mqtt_prop_serializer.c:addPropUint8/addPropUint16/addPropUint32helpers (exercised throughMQTTPropAdd_PayloadFormat,MQTTPropAdd_TopicAliasMaxandMQTTPropAdd_SessionExpiry) and inMQTTPropAdd_SubscriptionId: the buffer is large enough overall, butcurrentIndexleaves fewer bytes than needed to encode the property.MQTTPropAdd_SubscriptionId.MQTTPropAdd_UserProp.Coverage impact (lcov, branch coverage enabled):
core_mqtt_prop_serializer.c: lines 98.5% -> 100%, branches 171/182 (94.0%) -> 180/182 (98.9%)The two remaining branch directions in
addPropUtf8(thepropertyLength > SIZE_MAX - 2andpropertyLength + 2 > 268435456conditions) requirepropertyLength > 65535, which cannot be exercised by a test that passes the assert-enabled build due toassert( !CHECK_SIZE_T_OVERFLOWS_16BIT( propertyLength ) ); the public wrappers additionally validate the same bound before calling the helper.Test Steps
Both CI unit-test configurations pass locally (5/5 test suites):
Formatting verified with uncrustify 0.69.0 using the config from FreeRTOS/CI-CD-Github-Actions.
Checklist:
Related Issue
N/A
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.