Commit 80bef066 authored by Randeep's avatar Randeep

[IOT-2124] Added check after OICCalloc

Change-Id: Ia0ea3e17b4a3357d8c40309fc62967a25c5f2365
Signed-off-by: Randeep's avatarRandeep Singh <randeep.s@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/19591Reviewed-by: default avatarKevin Kane <kkane@microsoft.com>
Tested-by: default avatarjenkins-iotivity <jenkins@iotivity.org>
parent 7f8b0093
......@@ -218,11 +218,17 @@ OCStackResult OCCloudAclInviteUser(void* ctx,
OCRepPayload *payload = OCRepPayloadCreate();
if (!payload)
{
OIC_LOG(ERROR, TAG, "Memory Allocation failed!!!");
return OC_STACK_NO_MEMORY;
}
OCRepPayload **heplerPayload = OICCalloc(groupIds->length, sizeof(OCRepPayload *));
if (NULL == heplerPayload)
{
OCRepPayloadDestroy(payload);
OIC_LOG(ERROR, TAG, "Memory Allocation failed!!!");
return OC_STACK_NO_MEMORY;
}
for (i = 0; i < groupIds->length; i++)
{
heplerPayload[i] = OCRepPayloadCreate();
......
......@@ -752,6 +752,7 @@ OicSecAcl_t* CBORPayloadToCloudAcl(const uint8_t *cborPayload, const size_t size
cbor_parser_init(cborPayload, size, 0, &parser, &aclCbor);
OicSecAcl_t *acl = (OicSecAcl_t *) OICCalloc(1, sizeof(OicSecAcl_t));
VERIFY_NOT_NULL_RETURN(TAG, acl, ERROR, NULL);
// Enter ACL Map
CborValue aclMap = { .parser = NULL, .ptr = NULL, .remaining = 0, .extra = 0, .type = 0, .flags = 0 };
......
......@@ -222,6 +222,7 @@ OCStackResult CBORPayloadToAmacl(const uint8_t *cborPayload, size_t size,
cbor_parser_init(cborPayload, size, 0, &parser, &amaclCbor);
OicSecAmacl_t *headAmacl = (OicSecAmacl_t *)OICCalloc(1, sizeof(OicSecAmacl_t));
VERIFY_NOT_NULL_RETURN(TAG, headAmacl, ERROR, OC_STACK_NO_MEMORY);
CborValue amaclMap = { .parser = NULL };
cborFindResult = cbor_value_enter_container(&amaclCbor, &amaclMap);
......
......@@ -314,6 +314,7 @@ OicSecAcl_t* JSONToAclBin(const char * jsonStr)
{
OCStackResult ret = OC_STACK_ERROR;
OicSecAcl_t * headAcl = (OicSecAcl_t*)OICCalloc(1, sizeof(OicSecAcl_t));
VERIFY_NOT_NULL_RETURN(TAG, headAcl, ERROR, NULL);
cJSON *jsonRoot = NULL;
VERIFY_NOT_NULL(TAG, jsonStr, ERROR);
......@@ -817,6 +818,7 @@ OicSecPstat_t* JSONToPstatBin(const char * jsonStr)
VERIFY_SUCCESS(TAG, cJSON_Number == jsonObj->type, ERROR);
pstat->smLen = 1;
pstat->sm = (OicSecDpom_t*)OICCalloc(pstat->smLen, sizeof(OicSecDpom_t));
VERIFY_NOT_NULL(TAG, pstat->sm, ERROR);
pstat->sm[0] = (OicSecDpom_t)jsonObj->valueint;
ret = OC_STACK_OK;
......@@ -1034,7 +1036,7 @@ static OicSecAmacl_t* JSONToAmaclBin(const char * jsonStr)
{
OCStackResult ret = OC_STACK_ERROR;
OicSecAmacl_t * headAmacl = (OicSecAmacl_t*)OICCalloc(1, sizeof(OicSecAmacl_t));
VERIFY_NOT_NULL_RETURN(TAG, headAmacl, ERROR, NULL);
cJSON *jsonRoot = NULL;
cJSON *jsonAmacl = NULL;
......@@ -1059,6 +1061,7 @@ static OicSecAmacl_t* JSONToAmaclBin(const char * jsonStr)
headAmacl->resourcesLen = cJSON_GetArraySize(jsonRlistArray);
headAmacl->resources = (char**)OICCalloc(headAmacl->resourcesLen, sizeof(char*));
VERIFY_NOT_NULL(TAG, headAmacl->resources, ERROR);
size_t idxx = 0;
do
{
......
......@@ -2160,6 +2160,11 @@ OCStackResult SendDirectStackResponse(const CAEndpoint_t* endPoint, const uint16
{
respInfo.info.options =
(CAHeaderOption_t *)OICCalloc(respInfo.info.numOptions, sizeof(CAHeaderOption_t));
if (NULL == respInfo.info.options)
{
OIC_LOG(ERROR, TAG, "Calloc failed");
return OC_STACK_NO_MEMORY;
}
memcpy (respInfo.info.options, options,
sizeof(CAHeaderOption_t) * respInfo.info.numOptions);
......@@ -3378,10 +3383,19 @@ OCStackResult OCDoRequest(OCDoHandle *handle,
else
{
requestInfo.info.numOptions = numOptions;
requestInfo.info.options =
(CAHeaderOption_t*) OICCalloc(numOptions, sizeof(CAHeaderOption_t));
memcpy(requestInfo.info.options, (CAHeaderOption_t*)options,
numOptions * sizeof(CAHeaderOption_t));
if(requestInfo.info.numOptions)
{
requestInfo.info.options =
(CAHeaderOption_t*) OICCalloc(numOptions, sizeof(CAHeaderOption_t));
if (NULL == requestInfo.info.options)
{
OIC_LOG(ERROR, TAG, "Calloc failed");
result = OC_STACK_NO_MEMORY;
goto exit;
}
memcpy(requestInfo.info.options, (CAHeaderOption_t*)options,
numOptions * sizeof(CAHeaderOption_t));
}
}
CopyDevAddrToEndpoint(devAddr, &endpoint);
......
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