Commit 907be8be authored by ol.beketov's avatar ol.beketov Committed by Randeep

[IOT-2089] Realloc NULL checks added

Change-Id: Ie1b99a3815c8126e35576d4c3daa91c73ad66c6d
Signed-off-by: default avatarol.beketov <ol.beketov@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/19663Tested-by: default avatarjenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: default avatarDmitriy Zhuravlev <d.zhuravlev@samsung.com>
Reviewed-by: default avatarAndrii Shtompel <a.shtompel@samsung.com>
Reviewed-by: default avatarPhil Coval <philippe.coval@osg.samsung.com>
Reviewed-by: default avatardongik Lee <dongik.lee@samsung.com>
Reviewed-by: Randeep's avatarRandeep Singh <randeep.s@samsung.com>
parent 9ff7c633
......@@ -3526,13 +3526,16 @@ void GetDerKey(ByteArray_t * key, const char * usage)
return;
}
key->data = OICRealloc(key->data, ctx.buflen);
if (NULL == key->data)
uint8_t *tmp = OICRealloc(key->data, ctx.buflen);
if (NULL == tmp)
{
OICFree(key->data);
key->data = NULL;
OIC_LOG(ERROR, TAG, "Failed to allocate memory");
mbedtls_pem_free(&ctx);
return;
}
key->data = tmp;
memcpy(key->data, ctx.buf, ctx.buflen);
key->len = ctx.buflen;
......@@ -3541,7 +3544,15 @@ void GetDerKey(ByteArray_t * key, const char * usage)
}
else if(temp->privateData.encoding == OIC_ENCODING_DER)
{
key->data = OICRealloc(key->data, key->len + temp->privateData.len);
uint8_t *tmp = OICRealloc(key->data, key->len + temp->privateData.len);
if (NULL == tmp)
{
OICFree(key->data);
key->data = NULL;
OIC_LOG(ERROR, TAG, "Failed to allocate memory");
return;
}
key->data = tmp;
memcpy(key->data + key->len, temp->privateData.data, temp->privateData.len);
key->len += temp->privateData.len;
OIC_LOG_V(DEBUG, TAG, "Key for %s found", usage);
......
......@@ -806,14 +806,17 @@ void GetDerCrl(ByteArray_t* out)
out->len = 0;
out->data = OICRealloc(out->data, crl->len);
if (out->data)
uint8_t *tmp = OICRealloc(out->data, crl->len);
if (tmp)
{
out->data = tmp;
memcpy(out->data, crl->data, crl->len);
out->len = crl->len;
}
else
{
OICFree(out->data);
out->data = NULL;
OIC_LOG(ERROR, TAG, "Can't allocate memory for out->data");
}
DeleteCrl(crlRes);
......
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