From c22b1d43107c93c0a1fe600386a3e6a8422b083f Mon Sep 17 00:00:00 2001 From: Ziran Sun Date: Tue, 23 May 2017 11:33:53 +0100 Subject: [PATCH] Add Failure check for OCGetResourceIns() in OCRDDeleteWithDeviceId(). Bug: https://jira.iotivity.org/browse/IOT-1809 Change-Id: I1aac3d7fae0dfc5fbee4d9715b328d18bd492b14 Signed-off-by: Ziran Sun Reviewed-on: https://gerrit.iotivity.org/gerrit/20317 Tested-by: jenkins-iotivity Reviewed-by: Todd Malsbary Reviewed-by: Dan Mihai --- resource/csdk/resource-directory/src/rd_client.c | 16 +++++++++------- resource/csdk/stack/src/ocstack.c | 14 ++++++++++---- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/resource/csdk/resource-directory/src/rd_client.c b/resource/csdk/resource-directory/src/rd_client.c index d550ef2..66f8127 100644 --- a/resource/csdk/resource-directory/src/rd_client.c +++ b/resource/csdk/resource-directory/src/rd_client.c @@ -450,15 +450,17 @@ OCStackResult OCRDDeleteWithDeviceId(OCDoHandle *handle, const char *host, { OCResource *handle = (OCResource *) resourceHandles[j]; int64_t ins = 0; - OCGetResourceIns(handle, &ins); - int lenBufferRequired = snprintf((queryParam + queryLength), - (MAX_URI_LENGTH - queryLength), "&ins=%" PRId64, ins); - if (lenBufferRequired >= (MAX_URI_LENGTH - queryLength) || lenBufferRequired < 0) + if (OC_STACK_OK == OCGetResourceIns(handle, &ins)) { - return OC_STACK_INVALID_URI; + int lenBufferRequired = snprintf((queryParam + queryLength), + (MAX_URI_LENGTH - queryLength), "&ins=%" PRId64, ins); + if (lenBufferRequired >= (MAX_URI_LENGTH - queryLength) || lenBufferRequired < 0) + { + return OC_STACK_INVALID_URI; + } + queryLength += lenBufferRequired; + OIC_LOG_V(DEBUG, TAG, "queryParam [%s]", queryParam); } - queryLength += lenBufferRequired; - OIC_LOG_V(DEBUG, TAG, "queryParam [%s]", queryParam); } if (targetUriBufferRequired + queryLength + 1 > MAX_URI_LENGTH) diff --git a/resource/csdk/stack/src/ocstack.c b/resource/csdk/stack/src/ocstack.c index 6ec0c37..984158d 100755 --- a/resource/csdk/stack/src/ocstack.c +++ b/resource/csdk/stack/src/ocstack.c @@ -5997,11 +5997,17 @@ OCStackResult OCUpdateResourceInsWithResponse(const char *requestUri, if (resHandle) { int64_t resIns = 0; - OCGetResourceIns(resHandle, &resIns); - if (queryIns && queryIns == resIns) + if (OC_STACK_OK == OCGetResourceIns(resHandle, &resIns)) { - OCBindResourceInsToResource(resHandle, 0); - break; + if (queryIns && queryIns == resIns) + { + OCBindResourceInsToResource(resHandle, 0); + break; + } + } + else + { + OIC_LOG(ERROR, TAG, "Get resource instance failed!"); } } } -- 2.7.4