Fix ocserver sample code that causes memory corrupt.
authorZiran Sun <ziran.sun@samsung.com>
Wed, 31 May 2017 14:08:05 +0000 (15:08 +0100)
committerZiran Sun <ziran.sun@samsung.com>
Fri, 2 Jun 2017 10:08:14 +0000 (10:08 +0000)
Bug: https://jira.iotivity.org/browse/IOT-2381
Change-Id: I3aca7c79d97a2e4295568dbbb24de384b6993f50
Signed-off-by: Ziran Sun <ziran.sun@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/20497
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
resource/csdk/stack/samples/linux/SimpleClientServer/ocserver.cpp

index 1888173..40aa69b 100644 (file)
@@ -652,13 +652,14 @@ OCEntityHandlerCb (OCEntityHandlerFlag flag,
                 {
                     OIC_LOG_V(INFO, TAG, "accept version option exists");
                     OIC_LOG_BUFFER(INFO, TAG, vOptionData, MAX_HEADER_OPTION_DATA_LENGTH);
-                }
-                uint16_t acceptVersion = vOptionData[0]*256 + vOptionData[1];
-                if (OC_SPEC_VERSION_VALUE == acceptVersion)
-                {
-                    OIC_LOG_V(INFO, TAG, "accept version equals to default OC_SPEC_VERSION_VALUE.");
+                    uint16_t acceptVersion = vOptionData[0]*256 + vOptionData[1];
+                    if (OC_SPEC_VERSION_VALUE == acceptVersion)
+                    {
+                        OIC_LOG_V(INFO, TAG, "accept version equals to default OC_SPEC_VERSION_VALUE.");
+                    }
                 }
 
+                actualDataSize = 0;
                 OCHeaderOption* sendOptions = response.sendVendorSpecificHeaderOptions;
                 size_t numOptions = response.numSendVendorSpecificHeaderOptions;
                 // Check if the option header has already existed before adding it in.
@@ -702,7 +703,6 @@ OCEntityHandlerCb (OCEntityHandlerFlag flag,
                                       option3,
                                       optionDataSize3);
                 }
-                response.numSendVendorSpecificHeaderOptions = 2;
             }
 
             // Send the response