[IOT-2342] Fix a crash issue on secureresourcemanager.c
authorJaewook Jung <jw0213.jung@samsung.com>
Tue, 23 May 2017 05:26:46 +0000 (14:26 +0900)
committerUze Choi <uzchoi@samsung.com>
Tue, 23 May 2017 08:24:06 +0000 (08:24 +0000)
Add null checking for a resource object which could be NULL if server
receives a request message including resource uri which server doesn't
have.

Change-Id: Idf29a43aeca5a919c0b22d3f0cd9ce507c8935ab
Signed-off-by: Jaewook Jung <jw0213.jung@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/20297
Reviewed-by: Uze Choi <uzchoi@samsung.com>
Tested-by: Uze Choi <uzchoi@samsung.com>
resource/csdk/security/src/secureresourcemanager.c

index b95b122b207fa0c9a135bc5515b7ddeeab73b5ee..bd447b6158cbd34c5283e1b02fee35c9fc8f3d71 100644 (file)
@@ -167,32 +167,38 @@ static void SetResourceUriAndType(SRMRequestContext_t *context)
 
 static void SetDiscoverable(SRMRequestContext_t *context)
 {
-    OCResource *resource;
     if (NULL == context)
     {
         OIC_LOG_V(ERROR, TAG, "%s: Null context.", __func__);
         context->discoverable = DISCOVERABLE_NOT_KNOWN;
+        return;
     }
-    else if (NULL == context->resourceUri)
+    if (NULL == context->resourceUri)
     {
         OIC_LOG_V(ERROR, TAG, "%s: Null resourceUri.", __func__);
         context->discoverable = DISCOVERABLE_NOT_KNOWN;
+        return;
+    }
+
+    OCResource *resource = FindResourceByUri(context->resourceUri);
+    if (NULL == resource)
+    {
+        OIC_LOG_V(ERROR, TAG, "%s: Unkown resourceUri(%s).", __func__, context->resourceUri);
+        context->discoverable = DISCOVERABLE_NOT_KNOWN;
+        return;
+    }
+
+    if (OC_DISCOVERABLE == (resource->resourceProperties & OC_DISCOVERABLE))
+    {
+        context->discoverable = DISCOVERABLE_TRUE;
+        OIC_LOG_V(DEBUG, TAG, "%s: resource %s is OC_DISCOVERABLE.",
+                  __func__, context->resourceUri);
     }
     else
     {
-        resource = FindResourceByUri(context->resourceUri);
-        if (OC_DISCOVERABLE == (resource->resourceProperties & OC_DISCOVERABLE))
-        {
-            context->discoverable = DISCOVERABLE_TRUE;
-            OIC_LOG_V(DEBUG, TAG, "%s: resource %s is OC_DISCOVERABLE.",
-                __func__, context->resourceUri);
-        }
-        else
-        {
-            context->discoverable = DISCOVERABLE_FALSE;
-            OIC_LOG_V(DEBUG, TAG, "%s: resource %s is NOT OC_DISCOVERABLE.",
-                __func__, context->resourceUri);
-        }
+        context->discoverable = DISCOVERABLE_FALSE;
+        OIC_LOG_V(DEBUG, TAG, "%s: resource %s is NOT OC_DISCOVERABLE.",
+                  __func__, context->resourceUri);
     }
 }