Fixed issue with HeaderOptions not correctly being sent
authorErich Keane <erich.keane@intel.com>
Fri, 16 Jan 2015 22:46:53 +0000 (14:46 -0800)
committerAshok Babu Channa <ashok.channa@samsung.com>
Wed, 21 Jan 2015 06:55:08 +0000 (06:55 +0000)
If HeaderOptions count was greater than 1, the sender side did not correctly
allocate and copy the memory for it, resulting in the second headeroption being
an invalid read/copy, thus resulting in garbage data in the second HeaderOption.

This fix ensures that ALL header option data is correctly copied.  Validation
shows that the rst of the stack is working properly, so the correct data will
be transferred.

Change-Id: I08d9ccf8943bf7e85f6d24055b5f11881ba2bd24
Signed-off-by: Erich Keane <erich.keane@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/153
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Sudarshan Prasad <sudarshan.prasad@intel.com>
Reviewed-by: Sakthivel Samidurai <sakthivel.samidurai@intel.com>
Reviewed-by: Sashi Penta <sashi.kumar.penta@intel.com>
Reviewed-by: Ashok Babu Channa <ashok.channa@samsung.com>
Tested-by: Ashok Babu Channa <ashok.channa@samsung.com>
resource/csdk/connectivity/src/caremotehandler.c

index 6807623..1bf864c 100644 (file)
@@ -313,10 +313,11 @@ CARequestInfo_t *CACloneRequestInfo(const CARequestInfo_t *rep)
         clone->info.token = temp;
     }
 
-    if (rep->info.options != NULL)
+    if (rep->info.options != NULL && rep->info.numOptions > 0)
     {
         // save the options
-        clone->info.options = (CAHeaderOption_t *) OICMalloc(sizeof(CAHeaderOption_t));
+        clone->info.options =
+            (CAHeaderOption_t *) OICMalloc(sizeof(CAHeaderOption_t) * clone->info.numOptions);
         if (clone->info.options == NULL)
         {
             OIC_LOG(DEBUG, TAG, "CACloneRequestInfo Out of memory");
@@ -324,8 +325,9 @@ CARequestInfo_t *CACloneRequestInfo(const CARequestInfo_t *rep)
             OICFree(clone);
             return NULL;
         }
-        memset(clone->info.options, 0, sizeof(CAHeaderOption_t));
-        memcpy(clone->info.options, rep->info.options, sizeof(CAHeaderOption_t));
+        memcpy(clone->info.options,
+                rep->info.options,
+                sizeof(CAHeaderOption_t) * clone->info.numOptions);
     }
 
     if (rep->info.payload != NULL)