espressif / esp-aws-iot

AWS IoT SDK for ESP32 based chipsets
Apache License 2.0
257 stars 154 forks source link

MQTT_Subscribe does not self detect valid number of entries in subscription array... (CA-170) #77

Open SolidStateLEDLighting opened 2 years ago

SolidStateLEDLighting commented 2 years ago

I'm working with subscribing to topics with MQTT (mutual authentication demo). My final intent is to exercise Fleet Provisioning.

The subscription routines allow the designer to statically create space for multiple topics. In the demo code, a call to MQTT_Subscribe calculates the size of the static array as follows:

/* Send SUBSCRIBE packet.

The full size of the array is sent into the function BUT the function will fail when it tries to process an array entry that is invalid. The function doesn't stop processing at an empty entry. The return code is: MQTTBadParameter

The work-around must be to replace sizeof( pGlobalSubscriptionList ) / sizeof( MQTTSubscribeInfo_t ) with a hard number indicating the total number of subscription entries which are valid.

I assume you want the MQTT_Subscribe function to detect when an array element is not valid and stop processing the subscriptions at that point???

If this is NOT the intent, then you should use a variable like topic_count in place of sizeof( pGlobalSubscriptionList ) / sizeof( MQTTSubscribeInfo_t ) to indicate the intend of the parameter more clearly.

Working with Windows / VSC in C++