[IOT-2217] Fix crash in BuildIntrospectionResponseRepresentation.
authorTodd Malsbary <todd.malsbary@intel.com>
Fri, 5 May 2017 22:15:45 +0000 (15:15 -0700)
committerUze Choi <uzchoi@samsung.com>
Thu, 11 May 2017 01:38:37 +0000 (01:38 +0000)
Bug: https://jira.iotivity.org/browse/IOT-2217
Change-Id: Ibd07bb064557e67db6b62f3464acf7fc13311d7d
Signed-off-by: Todd Malsbary <todd.malsbary@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/19687
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Ashok Babu Channa <ashok.channa@samsung.com>
Reviewed-by: Srikrishna Gurugubelli <srikguru@microsoft.com>
resource/csdk/stack/src/ocresource.c

index 9a9a2c1..2e205ec 100755 (executable)
@@ -1090,7 +1090,7 @@ exit:
 OCStackResult BuildIntrospectionResponseRepresentation(const OCResource *resourcePtr,
     OCRepPayload** payload, OCDevAddr *devAddr)
 {
-    size_t dimensions[3] = { 0, 0, 0 };
+    size_t dimensions[MAX_REP_ARRAY_DEPTH] = { 0 };
     OCRepPayload *tempPayload = NULL;
     OCRepPayload **urlInfoPayload = NULL;
     OCStackResult ret = OC_STACK_OK;
@@ -1166,7 +1166,7 @@ OCStackResult BuildIntrospectionResponseRepresentation(const OCResource *resourc
     }
 
     // Add a urlInfo object for each endpoint supported
-    urlInfoPayload = (OCRepPayload **)OICMalloc(nCaEps * sizeof(OCRepPayload));
+    urlInfoPayload = (OCRepPayload **)OICCalloc(nCaEps, sizeof(OCRepPayload*));
     if (!urlInfoPayload)
     {
         OIC_LOG(ERROR, TAG, "Unable to allocate memory for urlInfo ");
@@ -1243,6 +1243,10 @@ exit:
         OCRepPayloadDestroy(tempPayload);
         if (urlInfoPayload)
         {
+            for (size_t i = 0; i < nCaEps; ++i)
+            {
+                OCRepPayloadDestroy(urlInfoPayload[i]);
+            }
             OICFree(urlInfoPayload);
         }
     }