Fix for crash at FindResourceByUri(). (#629) 02/218802/1
authorsenthil.gs@samsung.com <senthil.gs@samsung.com>
Wed, 27 Nov 2019 05:45:02 +0000 (11:15 +0530)
committerDoHyun Pyun <dh79.pyun@samsung.com>
Thu, 28 Nov 2019 07:28:37 +0000 (16:28 +0900)
NULL check was not there before accessing "pointer->uri" due to which segmentation fault has occurred.
So NULL check is done at two different places.

https://github.sec.samsung.net/RS7-IOTIVITY/IoTivity/pull/629
(cherry-picked from 727d5f58b67d83d3c82452b0afb7781bba59ec81)

Change-Id: I77878da7f89858235feafbc7b25a4e1fef39a52a
Signed-off-by: Senthil Kumar G S <senthil.gs@samsung.com>
Signed-off-by: DoHyun Pyun <dh79.pyun@samsung.com>
resource/csdk/stack/src/ocresource.c
resource/csdk/stack/src/ocstack.c

index bf82aa2..287244b 100644 (file)
@@ -555,6 +555,7 @@ OCStackResult BuildVirtualResourceResponse(const OCResource *resourcePtr,
     return OC_STACK_OK;
 }
 
+// TODO: headResource needs to be accessed in a thread-safe manner
 OCResource *FindResourceByUri(const char* resourceUri)
 {
     if(!resourceUri)
@@ -565,7 +566,7 @@ OCResource *FindResourceByUri(const char* resourceUri)
     OCResource * pointer = headResource;
     while (pointer)
     {
-        if (strcmp(resourceUri, pointer->uri) == 0)
+        if (pointer->uri && strcmp(resourceUri, pointer->uri) == 0)
         {
             return pointer;
         }
index 57c14d9..4c799b1 100644 (file)
@@ -5483,7 +5483,7 @@ OCResourceHandle OCGetResourceHandleAtUri(const char *uri)
 
     while (pointer)
     {
-        if (strncmp(uri, pointer->uri, MAX_URI_LENGTH) == 0)
+        if (pointer->uri && strncmp(uri, pointer->uri, MAX_URI_LENGTH) == 0)
         {
             OIC_LOG_V(DEBUG, TAG, "Found Resource %s", uri);
             return pointer;