From 7a1896e8dcbdd48442f4ca9b2f69ee52dfefa384 Mon Sep 17 00:00:00 2001 From: Erich Keane Date: Fri, 16 Jan 2015 14:46:53 -0800 Subject: [PATCH] Fixed issue with HeaderOptions not correctly being sent 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 Reviewed-on: https://gerrit.iotivity.org/gerrit/153 Tested-by: jenkins-iotivity Reviewed-by: Sudarshan Prasad Reviewed-by: Sakthivel Samidurai Reviewed-by: Sashi Penta Reviewed-by: Ashok Babu Channa Tested-by: Ashok Babu Channa --- resource/csdk/connectivity/src/caremotehandler.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/resource/csdk/connectivity/src/caremotehandler.c b/resource/csdk/connectivity/src/caremotehandler.c index 6807623..1bf864c 100644 --- a/resource/csdk/connectivity/src/caremotehandler.c +++ b/resource/csdk/connectivity/src/caremotehandler.c @@ -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) -- 2.7.4