From d2124971f17b1767127a7241ecc95d00633e5f3e Mon Sep 17 00:00:00 2001 From: Jaehong Jo Date: Mon, 29 Apr 2019 20:26:17 +0900 Subject: [PATCH] Fixed acl update issues When update aclresource then if using payload with not fixed lenght of rt list, occur error. And if an empty rel is received, it will be updated to the garbage value. https://github.sec.samsung.net/RS7-IOTIVITY/IoTivity/commit/35dc2c8878f87c7f9d4313102c1676cf13480d8e (cherry picked from 35dc2c8878f87c7f9d4313102c1676cf13480d8e) Change-Id: I1ecd9eb2e23c1c2c2e3a752585b73b62d3b24247 Signed-off-by: Jaehong Jo Signed-off-by: DoHyun Pyun --- resource/csdk/security/src/aclresource.c | 43 ++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/resource/csdk/security/src/aclresource.c b/resource/csdk/security/src/aclresource.c index f557a09..dc4b874 100644 --- a/resource/csdk/security/src/aclresource.c +++ b/resource/csdk/security/src/aclresource.c @@ -190,6 +190,7 @@ OicSecAce_t* DuplicateACE(const OicSecAce_t* ace) newRsrc->rel = (char*)OICMalloc(sizeof(char) * allocateSize); VERIFY_NON_NULL(TAG, newRsrc->rel, ERROR); OICStrcpy(newRsrc->rel, allocateSize, rsrc->rel); + newRsrc->rel[allocateSize - 1] = '\0'; } if(rsrc->types && 0 < rsrc->typeLen) @@ -1128,12 +1129,31 @@ OicSecAcl_t* CBORPayloadToAcl(const uint8_t *cborPayload, const size_t size) { cbor_value_get_array_length(&rMap, &rsrc->typeLen); VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding RT array length."); + + CborValue resourceTypes; + + if (rsrc->typeLen == 0) + { + cborFindResult = cbor_value_enter_container(&rMap, &resourceTypes); + VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Entering RT Array."); + + while (!cbor_value_at_end(&resourceTypes)) + { + rsrc->typeLen++; + cborFindResult = cbor_value_advance(&resourceTypes); + if (cborFindResult != CborNoError) + { + break; + } + } + VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding RT array length."); + } + VERIFY_SUCCESS(TAG, (0 != rsrc->typeLen), ERROR); rsrc->types = (char**)OICCalloc(rsrc->typeLen, sizeof(char*)); VERIFY_NON_NULL(TAG, rsrc->types, ERROR); - CborValue resourceTypes; cborFindResult = cbor_value_enter_container(&rMap, &resourceTypes); VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Entering RT Array."); @@ -1151,12 +1171,31 @@ OicSecAcl_t* CBORPayloadToAcl(const uint8_t *cborPayload, const size_t size) { cbor_value_get_array_length(&rMap, &rsrc->interfaceLen); VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding IF array length."); + + CborValue interfaces; + + if (rsrc->interfaceLen == 0) + { + cborFindResult = cbor_value_enter_container(&rMap, &interfaces); + VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Entering IF Array."); + + while (!cbor_value_at_end(&interfaces)) + { + rsrc->interfaceLen++; + cborFindResult = cbor_value_advance(&interfaces); + if (cborFindResult != CborNoError) + { + break; + } + } + VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding IF array length."); + } + VERIFY_SUCCESS(TAG, (0 != rsrc->interfaceLen), ERROR); rsrc->interfaces = (char**)OICCalloc(rsrc->interfaceLen, sizeof(char*)); VERIFY_NON_NULL(TAG, rsrc->interfaces, ERROR); - CborValue interfaces; cborFindResult = cbor_value_enter_container(&rMap, &interfaces); VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Entering IF Array."); -- 2.7.4