Fixed core dump during Security Discovery
authorjs126.lee <js126.lee@samsung.com>
Fri, 24 Feb 2017 08:16:18 +0000 (17:16 +0900)
committerRandeep Singh <randeep.s@samsung.com>
Thu, 2 Mar 2017 04:14:49 +0000 (04:14 +0000)
Issue : Core dump occur in (un)owned device discovery on provisionclient sample,
        when build option with SECURED=1 WITH_TCP=1 WITH_CLOUD=1.
Cause : Incorrect condition to set remoteId in OCHandleResponse.
        So, wrong type casting happen as OCDiscoveryPayload,
        and then core dump occure in OCCMDiscoveryResource function.
        (https://gerrit.iotivity.org/gerrit/#/c/15909)

Change-Id: I5a4c521ad14f8d5a6a9ec944cfdcfc3b705e409d
Signed-off-by: js126.lee <js126.lee@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/17497
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Nathan Heldt-Sheller <nathan.heldt-sheller@intel.com>
Reviewed-by: Kevin Kane <kkane@microsoft.com>
Reviewed-by: Phil Coval <philippe.coval@osg.samsung.com>
Reviewed-by: Randeep Singh <randeep.s@samsung.com>
resource/csdk/stack/src/ocstack.c

index b68af17..54c1657 100644 (file)
@@ -1491,6 +1491,7 @@ void OCHandleResponse(const CAEndpoint_t* endPoint, const CAResponseInfo_t* resp
             OIC_LOG(INFO, TAG, "Calling into application address space");
 
             OCClientResponse *response = NULL;
+            OCPayloadType type = PAYLOAD_TYPE_INVALID;
 
             response = (OCClientResponse *)OICCalloc(1, sizeof(*response));
             if (!response)
@@ -1513,7 +1514,6 @@ void OCHandleResponse(const CAEndpoint_t* endPoint, const CAResponseInfo_t* resp
             if(responseInfo->info.payload &&
                responseInfo->info.payloadSize)
             {
-                OCPayloadType type = PAYLOAD_TYPE_INVALID;
                 // check the security resource
                 if (SRMIsSecurityResourceURI(cbNode->requestUri))
                 {
@@ -1707,7 +1707,7 @@ void OCHandleResponse(const CAEndpoint_t* endPoint, const CAResponseInfo_t* resp
                 }
 #endif
                 // set remoteID(device ID) into OCClientResponse callback parameter
-                if (OC_REST_DISCOVER == cbNode->method)
+                if (OC_REST_DISCOVER == cbNode->method && PAYLOAD_TYPE_DISCOVERY == type)
                 {
                     OCDiscoveryPayload *payload = (OCDiscoveryPayload*) response->payload;
                     // Payload can be empty in case of error message.