fixed the crash for payload, when empty string is used.
authorjihwan.seo <jihwan.seo@samsung.com>
Fri, 7 Aug 2015 02:26:29 +0000 (11:26 +0900)
committerErich Keane <erich.keane@intel.com>
Mon, 10 Aug 2015 04:27:54 +0000 (04:27 +0000)
Change-Id: Ide824e447dec95cd56a32a21d290044a1571b7f7
Signed-off-by: jihwan.seo <jihwan.seo@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/2131
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Erich Keane <erich.keane@intel.com>
resource/csdk/connectivity/common/src/caremotehandler.c
resource/csdk/connectivity/src/caprotocolmessage.c

index e6ef079..48e5f56 100644 (file)
@@ -112,7 +112,7 @@ CARequestInfo_t *CACloneRequestInfo(const CARequestInfo_t *rep)
         clone->info.numOptions = 0;
     }
 
-    if (NULL != rep->info.payload)
+    if (NULL != rep->info.payload && 0 < rep->info.payloadSize)
     {
         // allocate payload field
         uint8_t *temp = OICMalloc(rep->info.payloadSize);
@@ -129,6 +129,11 @@ CARequestInfo_t *CACloneRequestInfo(const CARequestInfo_t *rep)
         // save the payload
         clone->info.payload = temp;
     }
+    else
+    {
+        clone->info.payload = NULL;
+        clone->info.payloadSize = 0;
+    }
 
     if (NULL != rep->info.resourceUri)
     {
@@ -243,7 +248,7 @@ CAResponseInfo_t *CACloneResponseInfo(const CAResponseInfo_t *rep)
         clone->info.numOptions = 0;
     }
 
-    if (NULL != rep->info.payload)
+    if (NULL != rep->info.payload && 0 < rep->info.payloadSize)
     {
         // allocate payload field
         uint8_t *temp = (uint8_t *) OICMalloc(rep->info.payloadSize);
@@ -260,6 +265,11 @@ CAResponseInfo_t *CACloneResponseInfo(const CAResponseInfo_t *rep)
         // save the payload
         clone->info.payload = temp;
     }
+    else
+    {
+        clone->info.payload = NULL;
+        clone->info.payloadSize = 0;
+    }
 
     if (NULL != rep->info.resourceUri)
     {
@@ -322,7 +332,6 @@ static void CADestroyInfoInternal(CAInfo_t *info)
     info->options = NULL;
     info->numOptions = 0;
 
-
     // free payload field
     OICFree((char *) info->payload);
     info->payload = NULL;
@@ -413,7 +422,7 @@ CAResult_t CACloneInfo(const CAInfo_t *info, CAInfo_t *clone)
         memcpy(clone->options, info->options, sizeof(CAHeaderOption_t) * info->numOptions);
     }
 
-    if (info->payload)
+    if (info->payload && 0 < info->payloadSize)
     {
         // allocate payload field
         uint8_t *temp = OICMalloc(info->payloadSize);
@@ -428,6 +437,11 @@ CAResult_t CACloneInfo(const CAInfo_t *info, CAInfo_t *clone)
         // save the payload
         clone->payload = temp;
     }
+    else
+    {
+        clone->payload = NULL;
+        clone->payloadSize = 0;
+    }
 
     if (info->resourceUri)
     {
index d6a48b7..a418a03 100644 (file)
@@ -304,7 +304,7 @@ coap_pdu_t *CAGeneratePDUImpl(code_t code, coap_list_t *options, const CAInfo_t
 
     if (enabledPayload || CA_ADAPTER_GATT_BTLE == endpoint->adapter)
     {
-        if (NULL != info->payload)
+        if (NULL != info->payload && 0 < info->payloadSize)
         {
             OIC_LOG(DEBUG, TAG, "payload is added");
             coap_add_data(pdu, info->payloadSize, (const unsigned char *) info->payload);