Commit 94bef05f authored by Oleksii Beketov's avatar Oleksii Beketov Committed by Randeep

Security and connectivity defects fix

Some minor defects (NULL checks and double frees) fixed.

Change-Id: I066a238a9379d45d1f377cc5a144c0bc0a97ccb7
Signed-off-by: default avatarOleksii Beketov <ol.beketov@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/17039Reviewed-by: default avatarDmitriy Zhuravlev <d.zhuravlev@samsung.com>
Tested-by: default avatarjenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Randeep's avatarRandeep Singh <randeep.s@samsung.com>
Signed-off-by: default avatarOleksii Beketov <ol.beketov@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/17319
parent 84476992
......@@ -189,6 +189,10 @@ CAResult_t CAConvertNameToAddr(const char *host, uint16_t port, struct sockaddr_
int r = getaddrinfo(host, NULL, &hints, &addrs);
if (r)
{
if (NULL != addrs)
{
freeaddrinfo(addrs);
}
#if defined(EAI_SYSTEM)
if (EAI_SYSTEM == r)
{
......
......@@ -872,13 +872,16 @@ OCStackResult CBORPayloadToCred(const uint8_t *cborPayload, size_t size,
return OC_STACK_ERROR;
}
OicSecCred_t *headCred = (OicSecCred_t *) OICCalloc(1, sizeof(OicSecCred_t));
OicSecCred_t *headCred = NULL;
// Enter CRED Root Map
CborValue CredRootMap = { .parser = NULL, .ptr = NULL, .remaining = 0, .extra = 0, .type = 0, .flags = 0 };
cborFindResult = cbor_value_enter_container(&credCbor, &CredRootMap);
VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Entering CRED Root Map.");
headCred = (OicSecCred_t *) OICCalloc(1, sizeof(OicSecCred_t));
VERIFY_NOT_NULL(TAG, headCred, ERROR);
while (cbor_value_is_valid(&CredRootMap))
{
char* tagName = NULL;
......@@ -918,6 +921,7 @@ OCStackResult CBORPayloadToCred(const uint8_t *cborPayload, size_t size,
else
{
cred = (OicSecCred_t *) OICCalloc(1, sizeof(OicSecCred_t));
VERIFY_NOT_NULL(TAG, cred, ERROR);
OicSecCred_t *temp = headCred;
while (temp->next)
{
......@@ -926,8 +930,6 @@ OCStackResult CBORPayloadToCred(const uint8_t *cborPayload, size_t size,
temp->next = cred;
}
VERIFY_NOT_NULL(TAG, cred, ERROR);
while(cbor_value_is_valid(&credMap) && cbor_value_is_text_string(&credMap))
{
char* name = NULL;
......
......@@ -363,23 +363,30 @@ OCStackResult CrlToCBORPayload(const OicSecCrl_t *crl, uint8_t **payload, size_t
ret = OC_STACK_OK;
exit:
if ((CborErrorOutOfMemory == cborEncoderResult) && (cborLen < CBOR_MAX_SIZE))
{
// reallocate and try again!
OICFree(outPayload);
// Since the allocated initial memory failed, double the memory.
cborLen += cbor_encoder_get_buffer_size(&encoder, encoder.end);
cborEncoderResult = CborNoError;
ret = CrlToCBORPayload(crl, payload, &cborLen, lastUpdate);
}
if ((CborNoError != cborEncoderResult) || (OC_STACK_OK != ret))
{
OICFree(outPayload);
outPayload = NULL;
*payload = NULL;
*size = 0;
ret = OC_STACK_ERROR;
if ((CborErrorOutOfMemory == cborEncoderResult) && (cborLen < CBOR_MAX_SIZE))
{
// Since the allocated initial memory failed, double the memory.
cborLen += cbor_encoder_get_buffer_size(&encoder, encoder.end);
cborEncoderResult = CborNoError;
ret = CrlToCBORPayload(crl, payload, &cborLen, lastUpdate);
if (OC_STACK_OK != ret)
{
outPayload = NULL;
*payload = NULL;
*size = 0;
ret = OC_STACK_ERROR;
}
}
else
{
outPayload = NULL;
*payload = NULL;
*size = 0;
ret = OC_STACK_ERROR;
}
}
return ret;
......
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