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, ...@@ -218,11 +218,17 @@ OCStackResult OCCloudAclInviteUser(void* ctx,
OCRepPayload *payload = OCRepPayloadCreate(); OCRepPayload *payload = OCRepPayloadCreate();
if (!payload) if (!payload)
{ {
OIC_LOG(ERROR, TAG, "Memory Allocation failed!!!");
return OC_STACK_NO_MEMORY; return OC_STACK_NO_MEMORY;
} }
OCRepPayload **heplerPayload = OICCalloc(groupIds->length, sizeof(OCRepPayload *)); 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++) for (i = 0; i < groupIds->length; i++)
{ {
heplerPayload[i] = OCRepPayloadCreate(); heplerPayload[i] = OCRepPayloadCreate();
......
...@@ -752,6 +752,7 @@ OicSecAcl_t* CBORPayloadToCloudAcl(const uint8_t *cborPayload, const size_t size ...@@ -752,6 +752,7 @@ OicSecAcl_t* CBORPayloadToCloudAcl(const uint8_t *cborPayload, const size_t size
cbor_parser_init(cborPayload, size, 0, &parser, &aclCbor); cbor_parser_init(cborPayload, size, 0, &parser, &aclCbor);
OicSecAcl_t *acl = (OicSecAcl_t *) OICCalloc(1, sizeof(OicSecAcl_t)); OicSecAcl_t *acl = (OicSecAcl_t *) OICCalloc(1, sizeof(OicSecAcl_t));
VERIFY_NOT_NULL_RETURN(TAG, acl, ERROR, NULL);
// Enter ACL Map // Enter ACL Map
CborValue aclMap = { .parser = NULL, .ptr = NULL, .remaining = 0, .extra = 0, .type = 0, .flags = 0 }; 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, ...@@ -222,6 +222,7 @@ OCStackResult CBORPayloadToAmacl(const uint8_t *cborPayload, size_t size,
cbor_parser_init(cborPayload, size, 0, &parser, &amaclCbor); cbor_parser_init(cborPayload, size, 0, &parser, &amaclCbor);
OicSecAmacl_t *headAmacl = (OicSecAmacl_t *)OICCalloc(1, sizeof(OicSecAmacl_t)); 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 }; CborValue amaclMap = { .parser = NULL };
cborFindResult = cbor_value_enter_container(&amaclCbor, &amaclMap); cborFindResult = cbor_value_enter_container(&amaclCbor, &amaclMap);
......
...@@ -314,6 +314,7 @@ OicSecAcl_t* JSONToAclBin(const char * jsonStr) ...@@ -314,6 +314,7 @@ OicSecAcl_t* JSONToAclBin(const char * jsonStr)
{ {
OCStackResult ret = OC_STACK_ERROR; OCStackResult ret = OC_STACK_ERROR;
OicSecAcl_t * headAcl = (OicSecAcl_t*)OICCalloc(1, sizeof(OicSecAcl_t)); OicSecAcl_t * headAcl = (OicSecAcl_t*)OICCalloc(1, sizeof(OicSecAcl_t));
VERIFY_NOT_NULL_RETURN(TAG, headAcl, ERROR, NULL);
cJSON *jsonRoot = NULL; cJSON *jsonRoot = NULL;
VERIFY_NOT_NULL(TAG, jsonStr, ERROR); VERIFY_NOT_NULL(TAG, jsonStr, ERROR);
...@@ -817,6 +818,7 @@ OicSecPstat_t* JSONToPstatBin(const char * jsonStr) ...@@ -817,6 +818,7 @@ OicSecPstat_t* JSONToPstatBin(const char * jsonStr)
VERIFY_SUCCESS(TAG, cJSON_Number == jsonObj->type, ERROR); VERIFY_SUCCESS(TAG, cJSON_Number == jsonObj->type, ERROR);
pstat->smLen = 1; pstat->smLen = 1;
pstat->sm = (OicSecDpom_t*)OICCalloc(pstat->smLen, sizeof(OicSecDpom_t)); pstat->sm = (OicSecDpom_t*)OICCalloc(pstat->smLen, sizeof(OicSecDpom_t));
VERIFY_NOT_NULL(TAG, pstat->sm, ERROR);
pstat->sm[0] = (OicSecDpom_t)jsonObj->valueint; pstat->sm[0] = (OicSecDpom_t)jsonObj->valueint;
ret = OC_STACK_OK; ret = OC_STACK_OK;
...@@ -1034,7 +1036,7 @@ static OicSecAmacl_t* JSONToAmaclBin(const char * jsonStr) ...@@ -1034,7 +1036,7 @@ static OicSecAmacl_t* JSONToAmaclBin(const char * jsonStr)
{ {
OCStackResult ret = OC_STACK_ERROR; OCStackResult ret = OC_STACK_ERROR;
OicSecAmacl_t * headAmacl = (OicSecAmacl_t*)OICCalloc(1, sizeof(OicSecAmacl_t)); OicSecAmacl_t * headAmacl = (OicSecAmacl_t*)OICCalloc(1, sizeof(OicSecAmacl_t));
VERIFY_NOT_NULL_RETURN(TAG, headAmacl, ERROR, NULL);
cJSON *jsonRoot = NULL; cJSON *jsonRoot = NULL;
cJSON *jsonAmacl = NULL; cJSON *jsonAmacl = NULL;
...@@ -1059,6 +1061,7 @@ static OicSecAmacl_t* JSONToAmaclBin(const char * jsonStr) ...@@ -1059,6 +1061,7 @@ static OicSecAmacl_t* JSONToAmaclBin(const char * jsonStr)
headAmacl->resourcesLen = cJSON_GetArraySize(jsonRlistArray); headAmacl->resourcesLen = cJSON_GetArraySize(jsonRlistArray);
headAmacl->resources = (char**)OICCalloc(headAmacl->resourcesLen, sizeof(char*)); headAmacl->resources = (char**)OICCalloc(headAmacl->resourcesLen, sizeof(char*));
VERIFY_NOT_NULL(TAG, headAmacl->resources, ERROR);
size_t idxx = 0; size_t idxx = 0;
do do
{ {
......
...@@ -2160,6 +2160,11 @@ OCStackResult SendDirectStackResponse(const CAEndpoint_t* endPoint, const uint16 ...@@ -2160,6 +2160,11 @@ OCStackResult SendDirectStackResponse(const CAEndpoint_t* endPoint, const uint16
{ {
respInfo.info.options = respInfo.info.options =
(CAHeaderOption_t *)OICCalloc(respInfo.info.numOptions, sizeof(CAHeaderOption_t)); (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, memcpy (respInfo.info.options, options,
sizeof(CAHeaderOption_t) * respInfo.info.numOptions); sizeof(CAHeaderOption_t) * respInfo.info.numOptions);
...@@ -3378,10 +3383,19 @@ OCStackResult OCDoRequest(OCDoHandle *handle, ...@@ -3378,10 +3383,19 @@ OCStackResult OCDoRequest(OCDoHandle *handle,
else else
{ {
requestInfo.info.numOptions = numOptions; requestInfo.info.numOptions = numOptions;
requestInfo.info.options = if(requestInfo.info.numOptions)
(CAHeaderOption_t*) OICCalloc(numOptions, sizeof(CAHeaderOption_t)); {
memcpy(requestInfo.info.options, (CAHeaderOption_t*)options, requestInfo.info.options =
numOptions * sizeof(CAHeaderOption_t)); (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); 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