[IOT-2756] Handle empty cert chain in role entry
authorAlex Kelley <alexke@microsoft.com>
Fri, 22 Sep 2017 21:36:11 +0000 (14:36 -0700)
committerRandeep Singh <randeep.s@samsung.com>
Wed, 27 Sep 2017 03:47:52 +0000 (03:47 +0000)
Update HandleDeleteRequest to return OC_EH_RESOURCE_DELETED when the role
entry does not contain any cert chains.

Change-Id: Id393a67da10c4f18f8fb69ed15de7782bdac9c70
Signed-off-by: Alex Kelley <alexke@microsoft.com>
resource/csdk/security/src/rolesresource.c

index 4566071dba57939e41ef8daff80bc567ab7a7dad..bdad20a30a5a2d6b13ff0c18ffadef3b43d5d07f 100644 (file)
@@ -966,19 +966,30 @@ static OCEntityHandlerResult HandleDeleteRequest(OCEntityHandlerRequest *ehReque
 
     InvalidateRoleCache(entry);
 
-    RoleCertChain_t *curr1 = NULL;
-    RoleCertChain_t *curr2 = NULL;
-    LL_FOREACH_SAFE(entry->chains, curr1, curr2)
+    if (NULL != entry->chains)
     {
-        // credId of zero means delete all creds; we never assign zero as a credId.
-        if ((0 == credId) || (curr1->credId == credId))
+        RoleCertChain_t *curr1 = NULL;
+        RoleCertChain_t *curr2 = NULL;
+        LL_FOREACH_SAFE(entry->chains, curr1, curr2)
         {
-            LL_DELETE(entry->chains, curr1);
-            FreeRoleCertChain(curr1);
-            ehRet = OC_EH_RESOURCE_DELETED;
-            break;
+            // credId of zero means delete all creds; we never assign zero as a credId.
+            if ((0 == credId) || (curr1->credId == credId))
+            {
+                LL_DELETE(entry->chains, curr1);
+                FreeRoleCertChain(curr1);
+                ehRet = OC_EH_RESOURCE_DELETED;
+                break;
+            }
         }
     }
+    else
+    {
+        /* No cert chains are present in the entry. */
+        OIC_LOG(WARNING, TAG, "No cert chains are present in the entry");
+        /* Request is successful since everything has been removed. */
+        ehRet = OC_EH_RESOURCE_DELETED;
+        goto exit;
+    }
 
 exit: