Fixed bug for result of static analysis. 41/13141/3
authorJihun Ha <jihun.ha@samsung.com>
Wed, 12 Oct 2016 13:27:36 +0000 (22:27 +0900)
committerUze Choi <uzchoi@samsung.com>
Thu, 13 Oct 2016 01:12:49 +0000 (01:12 +0000)
Change-Id: I6301a61d0e8fd8bfd21585a59455da50b2aabd14
Signed-off-by: Parkhi <h_w.park@samsung.com>
Signed-off-by: Jihun Ha <jihun.ha@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/13141
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/easy-setup/enrollee/src/resourcehandler.c
service/easy-setup/enrollee/src/resourcehandler.h
service/easy-setup/mediator/richsdk/src/EasySetup.cpp
service/easy-setup/mediator/richsdk/src/EnrolleeSecurity.cpp

index d0df225..707f55e 100755 (executable)
@@ -52,9 +52,9 @@ OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest, OCRep
 OCEntityHandlerResult ProcessPutRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload);
 OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload);
 void updateProvResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input);
-void updateWiFiResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input);
-void updateCloudResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input);
-void updateDevConfResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input);
+void updateWiFiResource(OCRepPayload* input);
+void updateCloudResource(OCRepPayload* input);
+void updateDevConfResource(OCRepPayload* input);
 const char *getResult(OCStackResult result);
 
 ESWiFiCB gWifiRsrcEvtCb = NULL;
@@ -278,24 +278,15 @@ void updateProvResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input)
         if(CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_BATCH))
         {
             // When Provisioning resource has a POST with BatchInterface
-            updateCloudResource(NULL, input);
-            updateWiFiResource(NULL, input);
-            updateDevConfResource(NULL, input);
+            updateCloudResource(input);
+            updateWiFiResource(input);
+            updateDevConfResource(input);
         }
     }
 }
 
-void updateWiFiResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input)
+void updateWiFiResource(OCRepPayload* input)
 {
-    if(ehRequest &&
-        strcmp(ehRequest->query, "") &&
-        !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT))
-    {
-        // In case of link list, batch interface
-        OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
-        return ;
-    }
-
     ESWiFiProvData* wiFiData = (ESWiFiProvData*)OICMalloc(sizeof(ESWiFiProvData));
 
     if(wiFiData == NULL)
@@ -365,17 +356,8 @@ void updateWiFiResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input)
     OICFree(wiFiData);
 }
 
-void updateCloudResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input)
+void updateCloudResource(OCRepPayload* input)
 {
-    if(ehRequest &&
-        strcmp(ehRequest->query, "") &&
-        !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT))
-    {
-        // In case of link list, batch interface
-        OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
-        return ;
-    }
-
     ESCloudProvData* cloudData = (ESCloudProvData*)OICMalloc(sizeof(ESCloudProvData));
 
     if(cloudData == NULL)
@@ -436,17 +418,8 @@ void updateCloudResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input)
     OICFree(cloudData);
 }
 
-void updateDevConfResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input)
+void updateDevConfResource(OCRepPayload* input)
 {
-    if(ehRequest &&
-        strcmp(ehRequest->query, "") &&
-        !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT))
-    {
-        // In case of link list, batch interface
-        OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
-        return ;
-    }
-
     ESDevConfProvData* devConfData = (ESDevConfProvData*)OICMalloc(sizeof(ESDevConfProvData));
 
     if(devConfData == NULL)
@@ -505,17 +478,8 @@ void updateDevConfResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* inpu
     OICFree(devConfData);
 }
 
-OCRepPayload* constructResponseOfWiFi(OCEntityHandlerRequest *ehRequest)
+OCRepPayload* constructResponseOfWiFi()
 {
-    if(ehRequest &&
-        strcmp(ehRequest->query, "") &&
-        !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT))
-    {
-        // In case of link list, batch interface
-        OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
-        return NULL;
-    }
-
     OCRepPayload* payload = OCRepPayloadCreate();
     if (!payload)
     {
@@ -550,17 +514,8 @@ OCRepPayload* constructResponseOfWiFi(OCEntityHandlerRequest *ehRequest)
     return payload;
 }
 
-OCRepPayload* constructResponseOfCloud(OCEntityHandlerRequest *ehRequest)
+OCRepPayload* constructResponseOfCloud()
 {
-    if(ehRequest &&
-        strcmp(ehRequest->query, "") &&
-        !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT))
-    {
-        // In case of link list, batch interface
-        OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
-        return NULL;
-    }
-
     OCRepPayload* payload = OCRepPayloadCreate();
     if (!payload)
     {
@@ -585,17 +540,8 @@ OCRepPayload* constructResponseOfCloud(OCEntityHandlerRequest *ehRequest)
     return payload;
 }
 
-OCRepPayload* constructResponseOfDevConf(OCEntityHandlerRequest *ehRequest)
+OCRepPayload* constructResponseOfDevConf()
 {
-    if(ehRequest &&
-        strcmp(ehRequest->query, "") &&
-        !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT))
-    {
-        // In case of link list, batch interface
-        OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
-        return NULL;
-    }
-
     OCRepPayload* payload = OCRepPayloadCreate();
     if (!payload)
     {
@@ -767,8 +713,6 @@ OCRepPayload* constructResponseOfProv(OCEntityHandlerRequest *ehRequest)
             OCRepPayload* head = payload;
             OCRepPayload* nextPayload = NULL;
 
-            childResCnt = 0;
-
             for(int i = 0 ; i < childResCnt ; ++i)
             {
                 nextPayload = arrayPayload[i];
@@ -814,21 +758,21 @@ OCRepPayload* constructResponseOfProv(OCEntityHandlerRequest *ehRequest)
             OCRepPayload* head = payload;
             OCRepPayload* nextPayload = NULL;
 
-            nextPayload = constructResponseOfWiFi(NULL);
+            nextPayload = constructResponseOfWiFi();
             if(nextPayload != NULL)
             {
                 payload->next = nextPayload;
                 payload = payload->next;
             }
 
-            nextPayload = constructResponseOfCloud(NULL);
+            nextPayload = constructResponseOfCloud();
             if(nextPayload != NULL)
             {
                 payload->next = nextPayload;
                 payload = payload->next;
             }
 
-            nextPayload = constructResponseOfDevConf(NULL);
+            nextPayload = constructResponseOfDevConf();
             if(nextPayload != NULL)
             {
                 payload->next = nextPayload;
@@ -1038,44 +982,38 @@ OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest, OCRep
     }
     else if(ehRequest->resource == gWiFiResource.handle)
     {
-        if(ehRequest->query &&
-            strcmp(ehRequest->query, "") &&
-            !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT))
+        if(CheckEhRequestPayload(ehRequest) != OC_EH_OK)
         {
             OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
             return OC_EH_BAD_REQ;
         }
         else
         {
-            getResp = constructResponseOfWiFi(ehRequest);
+            getResp = constructResponseOfWiFi();
         }
     }
     else if(ehRequest->resource == gCloudResource.handle)
     {
-        if(ehRequest->query &&
-            strcmp(ehRequest->query, "") &&
-            !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT))
+        if(CheckEhRequestPayload(ehRequest) != OC_EH_OK)
         {
             OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
             return OC_EH_BAD_REQ;
         }
         else
         {
-            getResp = constructResponseOfCloud(ehRequest);
+            getResp = constructResponseOfCloud();
         }
     }
     else if(ehRequest->resource == gDevConfResource.handle)
     {
-        if(ehRequest->query &&
-            strcmp(ehRequest->query, "") &&
-            !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT))
+        if(CheckEhRequestPayload(ehRequest) != OC_EH_OK)
         {
             OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
             return OC_EH_BAD_REQ;
         }
         else
         {
-            getResp = constructResponseOfDevConf(ehRequest);
+            getResp = constructResponseOfDevConf();
         }
     }
 
@@ -1125,44 +1063,38 @@ OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRe
     }
     else if(ehRequest->resource == gWiFiResource.handle)
     {
-        if(ehRequest->query &&
-            strcmp(ehRequest->query, "") &&
-            !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT))
+        if(CheckEhRequestPayload(ehRequest) != OC_EH_OK)
         {
             OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
             return OC_EH_BAD_REQ;
         }
         else
         {
-            updateWiFiResource(ehRequest, input);
+            updateWiFiResource(input);
         }
     }
     else if(ehRequest->resource == gCloudResource.handle)
     {
-        if(ehRequest->query &&
-            strcmp(ehRequest->query, "") &&
-            !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT))
+        if(CheckEhRequestPayload(ehRequest) != OC_EH_OK)
         {
             OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
             return OC_EH_BAD_REQ;
         }
         else
         {
-            updateCloudResource(ehRequest, input);
+            updateCloudResource(input);
         }
     }
     else if(ehRequest->resource == gDevConfResource.handle)
     {
-        if(ehRequest->query &&
-            strcmp(ehRequest->query, "") &&
-            !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT))
+        if(CheckEhRequestPayload(ehRequest) != OC_EH_OK)
         {
             OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
             return OC_EH_BAD_REQ;
         }
         else
         {
-            updateDevConfResource(ehRequest, input);
+            updateDevConfResource(input);
         }
     }
 
@@ -1173,15 +1105,15 @@ OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRe
     }
     else if(ehRequest->resource == gWiFiResource.handle)
     {
-        getResp = constructResponseOfWiFi(NULL);
+        getResp = constructResponseOfWiFi();
     }
     else if(ehRequest->resource == gCloudResource.handle)
     {
-        getResp = constructResponseOfCloud(NULL);
+        getResp = constructResponseOfCloud();
     }
     else if(ehRequest->resource == gDevConfResource.handle)
     {
-        getResp = constructResponseOfDevConf(NULL);
+        getResp = constructResponseOfDevConf();
     }
 
     if (!getResp)
@@ -1329,6 +1261,19 @@ OCStackResult SetEnrolleeErrCode(ESErrorCode esErrCode)
     return OC_STACK_OK;
 }
 
+OCEntityHandlerResult CheckEhRequestPayload(OCEntityHandlerRequest *ehRequest)
+{
+    if( !(ehRequest->query) ||
+                (ehRequest->query &&
+                (strcmp(ehRequest->query, "") && !CompareResourceInterface(ehRequest->query,
+                                                                        OC_RSRVD_INTERFACE_DEFAULT))))
+    {
+        OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
+        return OC_EH_BAD_REQ;
+    }
+    return OC_EH_OK;
+}
+
 const char *getResult(OCStackResult result)
 {
     switch (result)
index c59f1b7..5860450 100755 (executable)
@@ -86,6 +86,7 @@ OCStackResult DeleteEasySetupResources();
 OCStackResult SetDeviceProperty(ESDeviceProperty *deviceProperty);
 OCStackResult SetEnrolleeState(ESEnrolleeState esState);
 OCStackResult SetEnrolleeErrCode(ESErrorCode esErrCode);
+OCEntityHandlerResult CheckEhRequestPayload(OCEntityHandlerRequest *ehRequest);
 
 void RegisterWifiRsrcEventCallBack(ESWiFiCB);
 void RegisterCloudRsrcEventCallBack(ESCloudCB);
index da1beb8..73eab32 100755 (executable)
@@ -42,7 +42,7 @@ namespace OIC
         EasySetup* EasySetup::getInstance ()
         {
             if (s_instance == nullptr)
-           {
+            {
                 s_instance = new EasySetup ();
             }
             return s_instance;
index 7281db1..c9b4285 100755 (executable)
@@ -106,7 +106,11 @@ namespace OIC
 
             OCStackResult result = OC_STACK_ERROR;
             OicUuid_t uuid;
-            ConvertStrToUuid(m_ocResource->sid().c_str(), &uuid);
+            if(OC_STACK_OK != ConvertStrToUuid(m_ocResource->sid().c_str(), &uuid))
+            {
+                OIC_LOG(DEBUG, ENROLEE_SECURITY_TAG, "Convert to uuid from deviceID failed.");
+                return res;
+            }
 
             result = OCSecure::discoverSingleDevice(ES_SEC_DISCOVERY_TIMEOUT,
                                                     &uuid,
@@ -271,7 +275,6 @@ namespace OIC
             }
 
             OCUuidList_t *pUuidList = uuidList;
-
             while (pUuidList)
             {
                 std::string uuid;
@@ -281,10 +284,12 @@ namespace OIC
                     m_ocResource->sid().c_str(), uuid.c_str());
                 if(m_ocResource->sid() == uuid.c_str())
                 {
+                    OICFree(uuidList);
                     return true;
                 }
                 pUuidList = pUuidList->next;
             }
+            OICFree(uuidList);
             return false;
         }
 
@@ -307,7 +312,12 @@ namespace OIC
 
             OCStackResult result;
             OicUuid_t uuid;
-            ConvertStrToUuid(m_ocResource->sid().c_str(), &uuid);
+            if(OC_STACK_OK != ConvertStrToUuid(m_ocResource->sid().c_str(), &uuid))
+            {
+                OIC_LOG(DEBUG, ENROLEE_SECURITY_TAG, "Convert to uuid from deviceID failed.");
+                return res;
+            }
+
 
             result = OCSecure::discoverSingleDevice(ES_SEC_DISCOVERY_TIMEOUT,
                                                     &uuid,
@@ -437,7 +447,12 @@ namespace OIC
             OIC_LOG_V(DEBUG, ENROLEE_SECURITY_TAG, "Given cloudUuid: %s", cloudUuid.c_str());
 
             OicUuid_t uuid;
-            ConvertStrToUuid(cloudUuid.c_str(), &uuid);
+            if(OC_STACK_OK != ConvertStrToUuid(cloudUuid.c_str(), &uuid))
+            {
+                OIC_LOG(DEBUG, ENROLEE_SECURITY_TAG, "Convert to uuid from deviceID failed.");
+                return res;
+            }
+
 
             // Create Acl for Cloud Server to be provisioned to Enrollee
             OicSecAcl_t* acl = createAcl(uuid);