Fix GroupAction API of Things Manager.
authorHyunJun Kim <hyunjun2.kim@samsung.com>
Wed, 24 Dec 2014 04:43:38 +0000 (13:43 +0900)
committerSudarshan Prasad <sudarshan.prasad@intel.com>
Tue, 20 Jan 2015 22:05:05 +0000 (22:05 +0000)
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 <hyunjun2.kim@samsung.com>
(cherry picked from commit d2a9360615f1e0818f9b386c6d5b8321bd04d5c4)
Reviewed-on: https://gerrit.iotivity.org/gerrit/166
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Sudarshan Prasad <sudarshan.prasad@intel.com>
service/things-manager/sdk/src/GroupManager.cpp

index aed8734..d3ddab4 100644 (file)
@@ -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;
+    }
 }
 }