Commit 9d8a387c authored by Habib Virji's avatar Habib Virji

[IOT-995] Fix memory reallocation for security resources

When CborOutOfMemory is generated reallocation should be based on
encoder.ptr incremented value.

It also fixes allocation for security payload. It allocates value
based on the payload size.

Change-Id: I5213679d65e48bb91cd590d3cc654a6cd80b2af2
Signed-off-by: default avatarHabib Virji <>
Reviewed-on: default avatarjenkins-iotivity <>
Reviewed-by: default avatarChul Lee <>
Reviewed-by: default avatarYonggoo Kang <>
parent 8e60cf6d
......@@ -79,9 +79,20 @@ OCStackResult OCConvertPayload(OCPayload* payload, uint8_t** outPayload, size_t*
VERIFY_PARAM_NON_NULL(TAG, size, "size parameter is NULL");
OIC_LOG_V(INFO, TAG, "Converting payload of type %d", payload->type);
out = (uint8_t *)OICCalloc(1, curSize);
VERIFY_PARAM_NON_NULL(TAG, out, "Failed to allocate payload");
if (PAYLOAD_TYPE_SECURITY == payload->type)
size_t securityPayloadSize = ((OCSecurityPayload *)payload)->payloadSize;
if (securityPayloadSize > 0)
out = (uint8_t *)OICCalloc(1, ((OCSecurityPayload *)payload)->payloadSize);
VERIFY_PARAM_NON_NULL(TAG, out, "Failed to allocate security payload");
if (out == NULL)
out = (uint8_t *)OICCalloc(1, curSize);
VERIFY_PARAM_NON_NULL(TAG, out, "Failed to allocate payload");
err = OCConvertPayloadHelper(payload, out, &curSize);
......@@ -112,7 +123,8 @@ OCStackResult OCConvertPayload(OCPayload* payload, uint8_t** outPayload, size_t*
*size = curSize;
*outPayload = out;
OIC_LOG_V(DEBUG, TAG, "Payload Size: %zd Payload : %s \n", *size, *outPayload);
OIC_LOG_V(DEBUG, TAG, "Payload Size: %zd Payload : ", *size);
OIC_LOG_BUFFER(DEBUG, TAG, *outPayload, *size);
return OC_STACK_OK;
......@@ -170,17 +182,6 @@ static int64_t checkError(int64_t err, CborEncoder* encoder, uint8_t* outPayload
static int64_t OCConvertSecurityPayload(OCSecurityPayload* payload, uint8_t* outPayload,
size_t* size)
if (*size < payload->payloadSize)
uint8_t *out2 = (uint8_t *)OICRealloc(outPayload, payload->payloadSize);
if (!out2)
return CborErrorOutOfMemory;
outPayload = out2;
memcpy(outPayload, payload->securityData1, payload->payloadSize);
*size = payload->payloadSize;
......@@ -55,7 +55,9 @@ OCStackResult OCParsePayload(OCPayload **outPayload, OCPayloadType payloadType,
VERIFY_PARAM_NON_NULL(TAG, outPayload, "Conversion of outPayload failed");
VERIFY_PARAM_NON_NULL(TAG, payload, "Invalid cbor payload value");
OIC_LOG_V(INFO, TAG, "CBOR Parsing size: %zu", payloadSize);
OIC_LOG_V(INFO, TAG, "CBOR Parsing size: %zu of Payload Type: %d, Payload:",
payloadSize, payloadType);
OIC_LOG_BUFFER(DEBUG, TAG, payload, payloadSize);
CborParser parser;
CborValue rootValue;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment