Fixed acl update issues 33/208333/1
authorJaehong Jo <jaehong.jo@samsung.com>
Mon, 29 Apr 2019 11:26:17 +0000 (20:26 +0900)
committerDoHyun Pyun <dh79.pyun@samsung.com>
Mon, 24 Jun 2019 00:47:21 +0000 (09:47 +0900)
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 <jaehong.jo@samsung.com>
Signed-off-by: DoHyun Pyun <dh79.pyun@samsung.com>
resource/csdk/security/src/aclresource.c

index f557a09..dc4b874 100644 (file)
@@ -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.");