From: senthil.gs@samsung.com Date: Wed, 27 Nov 2019 05:45:02 +0000 (+0530) Subject: Fix for crash at FindResourceByUri(). (#629) X-Git-Tag: accepted/tizen/unified/20191201.221455~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F02%2F218802%2F1;p=platform%2Fupstream%2Fiotivity.git Fix for crash at FindResourceByUri(). (#629) 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 Signed-off-by: DoHyun Pyun --- diff --git a/resource/csdk/stack/src/ocresource.c b/resource/csdk/stack/src/ocresource.c index bf82aa2..287244b 100644 --- a/resource/csdk/stack/src/ocresource.c +++ b/resource/csdk/stack/src/ocresource.c @@ -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; } diff --git a/resource/csdk/stack/src/ocstack.c b/resource/csdk/stack/src/ocstack.c index 57c14d9..4c799b1 100644 --- a/resource/csdk/stack/src/ocstack.c +++ b/resource/csdk/stack/src/ocstack.c @@ -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;