From d2a9360615f1e0818f9b386c6d5b8321bd04d5c4 Mon Sep 17 00:00:00 2001 From: HyunJun Kim Date: Wed, 24 Dec 2014 13:43:38 +0900 Subject: [PATCH] Fix GroupAction API of Things Manager. Crash is occurred when some api of ThingsManager is called with null ocresource or null actionset. It will return OC_STACK_ERROR, if ocresource or actioset is null. Fix [IOT-199], [IOT-200], [IOT-201], [IOT-202] Change-Id: I1bf1070caaa4d06aad21aa26011474aae263a544 Signed-off-by: HyunJun Kim --- service/things-manager/sdk/src/GroupManager.cpp | 74 +++++++++++++++++-------- 1 file changed, 51 insertions(+), 23 deletions(-) diff --git a/service/things-manager/sdk/src/GroupManager.cpp b/service/things-manager/sdk/src/GroupManager.cpp index aed8734..d3ddab4 100644 --- a/service/things-manager/sdk/src/GroupManager.cpp +++ b/service/things-manager/sdk/src/GroupManager.cpp @@ -218,8 +218,8 @@ OCStackResult GroupManager::findCandidateResources(std::vector< std::string > re query.append(resourceTypes.at(i)); OCPlatform::findResource("", query.c_str(), std::function < void(std::shared_ptr < OCResource > resource) - > (std::bind(&GroupManager::onFoundResource, this, std::placeholders::_1, - waitsec))); + > (std::bind(&GroupManager::onFoundResource, this, + std::placeholders::_1, waitsec))); } if (waitsec != -1) @@ -319,8 +319,8 @@ void GroupManager::checkCollectionRepresentation(const OCRepresentation& rep, void(OCStackResult result, const unsigned int nonce, const std::string& hostAddress) >( std::bind(&GroupManager::collectionPresenceHandler, this, - std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, - hostAddress, oit->getUri()))); + std::placeholders::_1, std::placeholders::_2, + std::placeholders::_3, hostAddress, oit->getUri()))); if (result == OC_STACK_OK) { @@ -335,8 +335,8 @@ void GroupManager::checkCollectionRepresentation(const OCRepresentation& rep, } } -void GroupManager::onGetForPresence(const HeaderOptions& headerOptions, const OCRepresentation& rep, - const int eCode, CollectionPresenceCallback callback) +void GroupManager::onGetForPresence(const HeaderOptions& headerOptions, + const OCRepresentation& rep, const int eCode, CollectionPresenceCallback callback) { if (eCode == OC_STACK_OK) { @@ -529,44 +529,72 @@ OCStackResult GroupManager::addActionSet(std::shared_ptr< OCResource > resource, const ActionSet* newActionSet, PutCallback cb) { // BUILD message of ActionSet which it is included delimiter. - std::string message = getStringFromActionSet(newActionSet); - OCRepresentation rep; + if ((resource != NULL) && (newActionSet != NULL)) + { + std::string message = getStringFromActionSet(newActionSet); + OCRepresentation rep; - rep.setValue("ActionSet", message); + rep.setValue("ActionSet", message); - return resource->put(resource->getResourceTypes().front(), GROUP_INTERFACE, rep, - QueryParamsMap(), cb); + return resource->put(resource->getResourceTypes().front(), GROUP_INTERFACE, rep, + QueryParamsMap(), cb); + } + else + { + return OC_STACK_ERROR; + } } OCStackResult GroupManager::executeActionSet(std::shared_ptr< OCResource > resource, std::string actionsetName, PostCallback cb) { - OCRepresentation rep; + if (resource != NULL) + { + OCRepresentation rep; - rep.setValue("DoAction", actionsetName); - return resource->post(resource->getResourceTypes().front(), GROUP_INTERFACE, rep, - QueryParamsMap(), cb); + rep.setValue("DoAction", actionsetName); + return resource->post(resource->getResourceTypes().front(), GROUP_INTERFACE, rep, + QueryParamsMap(), cb); + } + else + { + return OC_STACK_ERROR; + } } OCStackResult GroupManager::getActionSet(std::shared_ptr< OCResource > resource, std::string actionsetName, PostCallback cb) { - OCRepresentation rep; + if (resource != NULL) + { + OCRepresentation rep; - rep.setValue("GetActionSet", actionsetName); + rep.setValue("GetActionSet", actionsetName); - return resource->post(resource->getResourceTypes().front(), GROUP_INTERFACE, rep, - QueryParamsMap(), cb); + return resource->post(resource->getResourceTypes().front(), GROUP_INTERFACE, rep, + QueryParamsMap(), cb); + } + else + { + return OC_STACK_ERROR; + } } OCStackResult GroupManager::deleteActionSet(std::shared_ptr< OCResource > resource, std::string actionsetName, PutCallback cb) { - OCRepresentation rep; + if (resource != NULL) + { + OCRepresentation rep; - rep.setValue("DelActionSet", actionsetName); + rep.setValue("DelActionSet", actionsetName); - return resource->put(resource->getResourceTypes().front(), GROUP_INTERFACE, rep, - QueryParamsMap(), cb); + return resource->put(resource->getResourceTypes().front(), GROUP_INTERFACE, rep, + QueryParamsMap(), cb); + } + else + { + return OC_STACK_ERROR; + } } } -- 2.7.4