Fix for bug IOT-759
authorShilpa Sodani <shilpa.a.sodani@intel.com>
Fri, 25 Sep 2015 20:21:58 +0000 (13:21 -0700)
committerSachin Agrawal <sachin.agrawal@intel.com>
Sun, 27 Sep 2015 23:51:48 +0000 (23:51 +0000)
Fixed the seg fault when no recurrence rule corresponding to period
rule was present.

Change-Id: I69989819d17ef7edf644a0efa512b051b18b7307
Signed-off-by: Shilpa Sodani <shilpa.a.sodani@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/3147
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Sachin Agrawal <sachin.agrawal@intel.com>
resource/csdk/security/src/aclresource.c
resource/csdk/security/src/policyengine.c

index 5ed446b..6d20938 100644 (file)
@@ -65,14 +65,25 @@ static void FreeACE(OicSecAcl_t *ace)
     }
     OICFree(ace->resources);
 
-    //Clean Period & Recurrence
-    for(i = 0; i < ace->prdRecrLen; i++)
+    //Clean Period
+    if(ace->periods)
     {
-        OICFree(ace->periods[i]);
-        OICFree(ace->recurrences[i]);
+        for(i = 0; i < ace->prdRecrLen; i++)
+        {
+            OICFree(ace->periods[i]);
+        }
+        OICFree(ace->periods);
+    }
+
+    //Clean Recurrence
+    if(ace->recurrences)
+    {
+        for(i = 0; i < ace->prdRecrLen; i++)
+        {
+            OICFree(ace->recurrences[i]);
+        }
+        OICFree(ace->recurrences);
     }
-    OICFree(ace->periods);
-    OICFree(ace->recurrences);
 
     // Clean Owners
     OICFree(ace->owners);
@@ -331,6 +342,7 @@ OicSecAcl_t * JSONToAclBin(const char * jsonStr)
             {
                 VERIFY_SUCCESS(TAG, cJSON_Array == jsonRecurObj->type,
                                ERROR);
+
                 if(acl->prdRecrLen > 0)
                 {
                     acl->recurrences = (char**)OICCalloc(acl->prdRecrLen,
@@ -341,11 +353,12 @@ OicSecAcl_t * JSONToAclBin(const char * jsonStr)
                     for(size_t i = 0; i < acl->prdRecrLen; i++)
                     {
                         jsonRecur = cJSON_GetArrayItem(jsonRecurObj, i);
+                        VERIFY_NON_NULL(TAG, jsonRecur, ERROR);
                         jsonObjLen = strlen(jsonRecur->valuestring) + 1;
                         acl->recurrences[i] = (char*)OICMalloc(jsonObjLen);
                         VERIFY_NON_NULL(TAG, acl->recurrences[i], ERROR);
                         OICStrcpy(acl->recurrences[i], jsonObjLen,
-                                  jsonRecur->valuestring);
+                              jsonRecur->valuestring);
                     }
                 }
             }
index 8284292..ef7b005 100644 (file)
@@ -228,6 +228,12 @@ static bool IsAccessWithinValidTime(const OicSecAcl_t *acl)
         return true;
     }
 
+    //periods & recurrences rules are paired.
+    if(NULL == acl->recurrences)
+    {
+        return false;
+    }
+
     for(size_t i = 0; i < acl->prdRecrLen; i++)
     {
         if(IOTVTICAL_VALID_ACCESS ==  IsRequestWithinValidTime(acl->periods[i],