Issue: Crash when received invalild cbob type in security resouces.
Jira : https://jira.iotivity.org/browse/IOT-1129
Resolved : Add checking type.
Patch 1: Add checking type.
Change-Id: Iee0ffa883586a680696c4173e8c33f08810e763b
Signed-off-by: js126.lee <js126.lee@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/8695
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Chul Lee <chuls.lee@samsung.com>
Reviewed-by: Randeep Singh <randeep.s@samsung.com>
char* tagName = NULL;
size_t len = 0;
CborType type = cbor_value_get_type(&aclMap);
- if (type == CborTextStringType)
+ if (type == CborTextStringType && cbor_value_is_text_string(&aclMap))
{
cborFindResult = cbor_value_dup_text_string(&aclMap, &tagName, &len, NULL);
VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding Name in ACL Map.");
char* acName = NULL;
size_t acLen = 0;
CborType acType = cbor_value_get_type(&aclistMap);
- if (acType == CborTextStringType)
+ if (acType == CborTextStringType && cbor_value_is_text_string(&aclistMap))
{
cborFindResult = cbor_value_dup_text_string(&aclistMap, &acName, &acLen, NULL);
VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding Name in ACLIST Map.");
char* name = NULL;
size_t len = 0;
CborType type = cbor_value_get_type(&aclMap);
- if (type == CborTextStringType)
+ if (type == CborTextStringType && cbor_value_is_text_string(&aclMap))
{
cborFindResult = cbor_value_dup_text_string(&aclMap, &name, &len, NULL);
VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding Name in ACL Map.");
if (name)
{
// Subject -- Mandatory
- if (strcmp(name, OIC_JSON_SUBJECTID_NAME) == 0)
+ if (strcmp(name, OIC_JSON_SUBJECTID_NAME) == 0 && cbor_value_is_text_string(&aclMap))
{
char *subject = NULL;
cborFindResult = cbor_value_dup_text_string(&aclMap, &subject, &len, NULL);
VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Entering Resource Map");
- while(cbor_value_is_valid(&rMap))
+ while(cbor_value_is_valid(&rMap) && cbor_value_is_text_string(&rMap))
{
char *rMapName = NULL;
size_t rMapNameLen = 0;
}
// Period -- Not mandatory
- if (strcmp(name, OIC_JSON_PERIOD_NAME) == 0)
+ if (strcmp(name, OIC_JSON_PERIOD_NAME) == 0 && cbor_value_is_array(&aclMap))
{
CborValue period = { .parser = NULL };
cborFindResult = cbor_value_get_array_length(&aclMap, &acl->prdRecrLen);
acl->periods = (char**)OICCalloc(acl->prdRecrLen, sizeof(char*));
VERIFY_NON_NULL(TAG, acl->periods, ERROR);
int i = 0;
- while (cbor_value_is_text_string(&period))
+ while (cbor_value_is_text_string(&period) && cbor_value_is_text_string(&period))
{
cborFindResult = cbor_value_dup_text_string(&period, &acl->periods[i++],
&len, NULL);
acl->recurrences = (char**)OICCalloc(acl->prdRecrLen, sizeof(char*));
VERIFY_NON_NULL(TAG, acl->recurrences, ERROR);
int i = 0;
- while (cbor_value_is_text_string(&recurrences))
+ while (cbor_value_is_text_string(&recurrences) && cbor_value_is_text_string(&recurrences))
{
cborFindResult = cbor_value_dup_text_string(&recurrences,
&acl->recurrences[i++], &len, NULL);
}
// TODO : Need to modify headAcl->owners[0].id to headAcl->rowner based on RAML spec.
- if (strcmp(tagName, OIC_JSON_ROWNERID_NAME) == 0)
+ if (strcmp(tagName, OIC_JSON_ROWNERID_NAME) == 0 && cbor_value_is_text_string(&aclMap))
{
char *stRowner = NULL;
cborFindResult = cbor_value_dup_text_string(&aclMap, &stRowner, &len, NULL);
cborFindResult = cbor_value_enter_container(&amaclCbor, &amaclMap);
VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Entering Amacl Map.");
- while(cbor_value_is_valid(&amaclMap))
+ while(cbor_value_is_valid(&amaclMap) && cbor_value_is_text_string(&amaclMap))
{
char *name = NULL;
size_t len = 0;
cborFindResult = cbor_value_enter_container(&amaclMap, &rsrcMap);
VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Entering Resource Map");
- while(cbor_value_is_valid(&rsrcMap))
+ while(cbor_value_is_valid(&rsrcMap) && cbor_value_is_text_string(&rsrcMap))
{
// resource name
char *rsrcName = NULL;
cborFindResult = cbor_value_enter_container(&rsrcArray, &rMap);
VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Entering Rlist Map");
- while(cbor_value_is_valid(&rMap))
+ while(cbor_value_is_valid(&rMap) && cbor_value_is_text_string(&rMap))
{
char *rMapName = NULL;
size_t rMapNameLen = 0;
VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Entering AMS Array Container.");
headAmacl->amss = (OicUuid_t *)OICCalloc(headAmacl->amssLen, sizeof(*headAmacl->amss));
VERIFY_NON_NULL(TAG, headAmacl->amss, ERROR);
- while (cbor_value_is_valid(&amsArray))
+ while (cbor_value_is_valid(&amsArray) && cbor_value_is_text_string(&amsArray))
{
char *amssId = NULL;
cborFindResult = cbor_value_dup_text_string(&amsArray, &amssId, &len, NULL);
}
// Rowner -- Mandatory
- if (0 == strcmp(OIC_JSON_ROWNERID_NAME, name))
+ if (0 == strcmp(OIC_JSON_ROWNERID_NAME, name) && cbor_value_is_text_string(&amaclMap))
{
char *stRowner = NULL;
cborFindResult = cbor_value_dup_text_string(&amaclMap, &stRowner, &len, NULL);
char* tagName = NULL;
size_t len = 0;
CborType type = cbor_value_get_type(&CredRootMap);
- if (type == CborTextStringType)
+ if (type == CborTextStringType && cbor_value_is_text_string(&CredRootMap))
{
cborFindResult = cbor_value_dup_text_string(&CredRootMap, &tagName, &len, NULL);
VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding Name in CRED Root Map.");
VERIFY_NON_NULL(TAG, cred, ERROR);
- while(cbor_value_is_valid(&credMap))
+ while(cbor_value_is_valid(&credMap) && cbor_value_is_text_string(&credMap))
{
char* name = NULL;
CborType type = cbor_value_get_type(&credMap);
{
char* privname = NULL;
CborType type = cbor_value_get_type(&privateMap);
- if (type == CborTextStringType)
+ if (type == CborTextStringType && cbor_value_is_text_string(&privateMap))
{
cborFindResult = cbor_value_dup_text_string(&privateMap, &privname,
&len, NULL);
if (privname)
{
// PrivateData::privdata -- Mandatory
- if (strcmp(privname, OIC_JSON_DATA_NAME) == 0)
+ if (strcmp(privname, OIC_JSON_DATA_NAME) == 0 && cbor_value_is_byte_string(&privateMap))
{
cborFindResult = cbor_value_dup_byte_string(&privateMap, &cred->privateData.data,
&cred->privateData.len, NULL);
{
char* pubname = NULL;
CborType type = cbor_value_get_type(&pubMap);
- if (type == CborTextStringType)
+ if (type == CborTextStringType && cbor_value_is_text_string(&pubMap))
{
cborFindResult = cbor_value_dup_text_string(&pubMap, &pubname,
&len, NULL);
if (pubname)
{
// PrivateData::privdata -- Mandatory
- if (strcmp(pubname, OIC_JSON_DATA_NAME) == 0)
+ if (strcmp(pubname, OIC_JSON_DATA_NAME) == 0 && cbor_value_is_byte_string(&pubMap))
{
cborFindResult = cbor_value_dup_byte_string(&pubMap, &cred->publicData.data,
&cred->publicData.len, NULL);
}
//ROwner -- Mandatory
- if (strcmp(tagName, OIC_JSON_ROWNERID_NAME) == 0)
+ if (strcmp(tagName, OIC_JSON_ROWNERID_NAME) == 0 && cbor_value_is_text_string(&CredRootMap))
{
char *stRowner = NULL;
cborFindResult = cbor_value_dup_text_string(&CredRootMap, &stRowner, &len, NULL);
int i = 0;
size_t len = 0;
- while (cbor_value_is_valid(&oxmType))
+ while (cbor_value_is_valid(&oxmType) && cbor_value_is_text_string(&oxmType))
{
cborFindResult = cbor_value_dup_text_string(&oxmType, &doxm->oxmType[i++],
&len, NULL);
VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Entering oxmName Array.")
int i = 0;
- while (cbor_value_is_valid(&oxm))
+ while (cbor_value_is_valid(&oxm) && cbor_value_is_integer(&oxm))
{
cborFindResult = cbor_value_get_int(&oxm, (int *) &doxm->oxm[i++]);
VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding oxmName Value")
dpair = (OicSecDpairing_t *)OICCalloc(1, sizeof(*dpair));
VERIFY_NON_NULL(TAG, dpair, ERROR);
- while (cbor_value_is_valid(&dpairMap))
+ while (cbor_value_is_valid(&dpairMap) && cbor_value_is_text_string(&dpairMap))
{
char *name = NULL;
size_t len = 0;
VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Advancing a value in DPair map");
type = cbor_value_get_type(&dpairMap);
- if (0 == strcmp(OIC_JSON_SPM_NAME, name))
+ if (0 == strcmp(OIC_JSON_SPM_NAME, name) && cbor_value_is_integer(&dpairMap))
{
cborFindResult = cbor_value_get_int(&dpairMap, (int *) &dpair->spm);
VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding SPM Value");
char *name = NULL;
size_t len = 0;
CborType type = cbor_value_get_type(&pconfMap);
- if (type == CborTextStringType)
+ if (type == CborTextStringType && cbor_value_is_text_string(&pconfMap))
{
cborFindResult = cbor_value_dup_text_string(&pconfMap, &name, &len, NULL);
VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed to get value");
if (name)
{
//EDP -- Mandatory
- if(0 == strcmp(OIC_JSON_EDP_NAME, name))
+ if(0 == strcmp(OIC_JSON_EDP_NAME, name) && cbor_value_is_boolean(&pconfMap))
{
cborFindResult = cbor_value_get_boolean(&pconfMap, &pconf->edp);
VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed to get value");
cborFindResult = cbor_value_enter_container(&pconfMap, &prm);
VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed to eneter array");
- while (cbor_value_is_valid(&prm))
+ while (cbor_value_is_valid(&prm) && cbor_value_is_integer(&prm))
{
cborFindResult = cbor_value_get_int(&prm, (int *)&pconf->prm[i++]);
VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed to get value");
}
}
//PIN -- Mandatory
- if (0 == strcmp(OIC_JSON_PIN_NAME, name))
+ if (0 == strcmp(OIC_JSON_PIN_NAME, name) && cbor_value_is_byte_string(&pconfMap))
{
uint8_t *pin = NULL;
cborFindResult = cbor_value_dup_byte_string(&pconfMap, &pin, &len, NULL);
char* name = NULL;
size_t len = 0;
CborType type = cbor_value_get_type(&pdAclMap);
- if (type == CborTextStringType)
+ if (type == CborTextStringType && cbor_value_is_text_string(&pdAclMap))
{
cborFindResult = cbor_value_dup_text_string(&pdAclMap, &name,
&len, NULL);
if (name)
{
// Resources -- Mandatory
- if (strcmp(name, OIC_JSON_RESOURCES_NAME) == 0)
+ if (strcmp(name, OIC_JSON_RESOURCES_NAME) == 0 && cbor_value_is_array(&pdAclMap))
{
int i = 0;
CborValue resources = { .parser = NULL };
cborFindResult = cbor_value_enter_container(&resources, &rMap);
VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Entering Resource Map");
- while(cbor_value_is_valid(&rMap))
+ while(cbor_value_is_valid(&rMap) && cbor_value_is_text_string(&rMap))
{
char *rMapName = NULL;
size_t rMapNameLen = 0;
}
// Permissions -- Mandatory
- if (strcmp(name, OIC_JSON_PERMISSION_NAME) == 0)
+ if (strcmp(name, OIC_JSON_PERMISSION_NAME) == 0 && cbor_value_is_unsigned_integer(&pdAclMap))
{
cborFindResult = cbor_value_get_uint64(&pdAclMap,
(uint64_t *) &pdacl->permission);
}
// Period -- Not mandatory
- if (strcmp(name, OIC_JSON_PERIODS_NAME) == 0)
+ if (strcmp(name, OIC_JSON_PERIODS_NAME) == 0 && cbor_value_is_array(&pdAclMap))
{
int i = 0;
CborValue period = { .parser = NULL };
pdacl->periods = (char **) OICCalloc(pdacl->prdRecrLen, sizeof(char*));
VERIFY_NON_NULL(TAG, pdacl->periods, ERROR);
- while (cbor_value_is_text_string(&period))
+ while (cbor_value_is_text_string(&period) && cbor_value_is_text_string(&period))
{
cborFindResult = cbor_value_dup_text_string(&period,
&pdacl->periods[i++], &len, NULL);
}
// Recurrence -- Not mandatory
- if (strcmp(name, OIC_JSON_RECURRENCES_NAME) == 0)
+ if (strcmp(name, OIC_JSON_RECURRENCES_NAME) == 0 && cbor_value_is_array(&pdAclMap))
{
int i = 0;
CborValue recurrences = { .parser = NULL };
pdacl->recurrences = (char **) OICCalloc(pdacl->prdRecrLen, sizeof(char*));
VERIFY_NON_NULL(TAG, pdacl->recurrences, ERROR);
- while (cbor_value_is_text_string(&recurrences))
+ while (cbor_value_is_text_string(&recurrences) && cbor_value_is_text_string(&recurrences))
{
cborFindResult = cbor_value_dup_text_string(&recurrences,
&pdacl->recurrences[i++], &len, NULL);
}
//PDDev -- Mandatory
- if (strcmp(name, OIC_JSON_PDDEV_LIST_NAME) == 0)
+ if (strcmp(name, OIC_JSON_PDDEV_LIST_NAME) == 0 && cbor_value_is_array(&pconfMap))
{
int i = 0;
CborValue pddevs = { .parser = NULL };
pconf->pddevs = (OicUuid_t *)OICMalloc(pconf->pddevLen * sizeof(OicUuid_t));
VERIFY_NON_NULL(TAG, pconf->pddevs, ERROR);
- while (cbor_value_is_valid(&pddevs))
+ while (cbor_value_is_valid(&pddevs) && cbor_value_is_text_string(&pddevs))
{
char *pddev = NULL;
cborFindResult = cbor_value_dup_text_string(&pddevs, &pddev, &len, NULL);
}
//Mandatory - Device Id
- if (0 == strcmp(OIC_JSON_DEVICE_ID_NAME, name))
+ if (0 == strcmp(OIC_JSON_DEVICE_ID_NAME, name) && cbor_value_is_text_string(&pconfMap))
{
char *deviceId = NULL;
cborFindResult = cbor_value_dup_text_string(&pconfMap, &deviceId, &len, NULL);
}
// ROwner -- Mandatory
- if (0 == strcmp(OIC_JSON_ROWNERID_NAME, name))
+ if (0 == strcmp(OIC_JSON_ROWNERID_NAME, name) && cbor_value_is_text_string(&pconfMap))
{
char *rowner = NULL;
cborFindResult = cbor_value_dup_text_string(&pconfMap, &rowner, &len, NULL);
type = cbor_value_get_type(&svcMap);
// Service Device Identity
- if (0 == strcmp(OIC_JSON_SERVICE_DEVICE_ID, name))
+ if (0 == strcmp(OIC_JSON_SERVICE_DEVICE_ID, name) && cbor_value_is_byte_string(&svcMap))
{
uint8_t *subjectId = NULL;
cborFindResult = cbor_value_dup_byte_string(&svcMap, &subjectId, &len, NULL);
OICFree(subjectId);
}
// Service Type
- if (0 == strcmp(OIC_JSON_SERVICE_TYPE, name))
+ if (0 == strcmp(OIC_JSON_SERVICE_TYPE, name) && cbor_value_is_integer(&svcMap))
{
cborFindResult = cbor_value_get_int(&svcMap, (int *) &svc->svct);
VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed to Find SVCT.");
}
// Owners -- Mandatory
- if (0 == strcmp(OIC_JSON_OWNERS_NAME, name))
+ if (0 == strcmp(OIC_JSON_OWNERS_NAME, name) && cbor_value_is_array(&svcMap))
{
int i = 0;
CborValue owners = { .parser = NULL };
svc->owners = (OicUuid_t *)OICCalloc(svc->ownersLen, sizeof(*svc->owners));
VERIFY_NON_NULL(TAG, svc->owners, ERROR);
- while (cbor_value_is_valid(&owners))
+ while (cbor_value_is_valid(&owners) && cbor_value_is_byte_string(&owners))
{
uint8_t *owner = NULL;
cborFindResult = cbor_value_dup_byte_string(&owners, &owner, &len, NULL);