From 65583a688701d3745ec2f8200c4d2041aefd27f5 Mon Sep 17 00:00:00 2001 From: tomoaki Date: Fri, 4 Oct 2019 21:12:00 +0900 Subject: [PATCH] Add Invalid TopicId check. Signed-off-by: tomoaki --- MQTTSNGateway/src/MQTTSNGWClientList.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/MQTTSNGateway/src/MQTTSNGWClientList.cpp b/MQTTSNGateway/src/MQTTSNGWClientList.cpp index 5452765..524b3b6 100644 --- a/MQTTSNGateway/src/MQTTSNGWClientList.cpp +++ b/MQTTSNGateway/src/MQTTSNGWClientList.cpp @@ -416,10 +416,16 @@ Client* ClientList::createClient(SensorNetAddress* addr, MQTTSNString* clientId, Client* ClientList::createPredefinedTopic( MQTTSNString* clientId, string topicName, uint16_t topicId, bool aggregate) { + if ( topicId == 0 ) + { + WRITELOG("Invalid TopicId. Predefined Topic %s, TopicId is 0. \n", topicName.c_str()); + return nullptr; + } + if ( strcmp(clientId->cstring, common_topic) == 0 ) { theGateway->getTopics()->add((const char*)topicName.c_str(), topicId); - return 0; + return nullptr; } else { @@ -427,7 +433,7 @@ Client* ClientList::createPredefinedTopic( MQTTSNString* clientId, string topicN if ( _authorize && client == nullptr ) { - return 0; + return nullptr; } /* anonimous clients */