From fce6ec479dfb24688cfd9b7644ef17a1367833b7 Mon Sep 17 00:00:00 2001 From: Archit Aggarwal Date: Tue, 21 Jul 2020 17:01:00 -0700 Subject: [PATCH] Port CBMC recognized undefined behavior fixes from C-SDK v4_beta (#157) --- .../standard/mqtt/src/iot_mqtt_subscription.c | 17 ++++++++++++----- .../c_sdk/standard/mqtt/src/iot_mqtt_validate.c | 3 ++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta1/c_sdk/standard/mqtt/src/iot_mqtt_subscription.c b/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta1/c_sdk/standard/mqtt/src/iot_mqtt_subscription.c index 37b6c63846..831955396a 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta1/c_sdk/standard/mqtt/src/iot_mqtt_subscription.c +++ b/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta1/c_sdk/standard/mqtt/src/iot_mqtt_subscription.c @@ -668,11 +668,18 @@ bool IotMqtt_IsSubscribed( IotMqttConnection_t mqttConnection, * function is running. */ IotMutex_Lock( &( mqttConnection->subscriptionMutex ) ); - /* Search for a matching subscription. */ - pSubscriptionLink = IotListDouble_FindFirstMatch( &( mqttConnection->subscriptionList ), - NULL, - _topicMatch, - &topicMatchParams ); + if( pTopicFilter == NULL ) + { + IotLogError( "Topic filter must be set." ); + } + else + { + /* Search for a matching subscription. */ + pSubscriptionLink = IotListDouble_FindFirstMatch( &( mqttConnection->subscriptionList ), + NULL, + _topicMatch, + &topicMatchParams ); + } /* Check if a matching subscription was found. */ if( pSubscriptionLink != NULL ) diff --git a/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta1/c_sdk/standard/mqtt/src/iot_mqtt_validate.c b/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta1/c_sdk/standard/mqtt/src/iot_mqtt_validate.c index cdcca62f0d..950d992971 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta1/c_sdk/standard/mqtt/src/iot_mqtt_validate.c +++ b/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta1/c_sdk/standard/mqtt/src/iot_mqtt_validate.c @@ -619,7 +619,8 @@ bool _IotMqtt_ValidateConnect( const IotMqttConnectInfo_t * pConnectInfo ) /* If will info is provided, check that it is valid. */ if( pConnectInfo->pWillInfo != NULL ) { - status = _IotMqtt_ValidateLwtPublish( pConnectInfo->awsIotMqttMode, + status = ( pConnectInfo->pWillInfo->pPayload != NULL ) && + _IotMqtt_ValidateLwtPublish( pConnectInfo->awsIotMqttMode, pConnectInfo->pWillInfo ); } }