From f729d72cc08d8accc5a0ccbbb791b1e79167e2f9 Mon Sep 17 00:00:00 2001 From: Shilpa Sodani Date: Fri, 25 Sep 2015 13:21:58 -0700 Subject: [PATCH] Fix for bug IOT-759 Fixed the seg fault when no recurrence rule corresponding to period rule was present. Change-Id: I69989819d17ef7edf644a0efa512b051b18b7307 Signed-off-by: Shilpa Sodani Reviewed-on: https://gerrit.iotivity.org/gerrit/3147 Tested-by: jenkins-iotivity Reviewed-by: Sachin Agrawal (cherry picked from commit 3382a044ea795e2335b96fb36139c6f217616c27) Reviewed-on: https://gerrit.iotivity.org/gerrit/3167 --- resource/csdk/security/src/aclresource.c | 27 ++++++++++++++++++++------- resource/csdk/security/src/policyengine.c | 6 ++++++ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/resource/csdk/security/src/aclresource.c b/resource/csdk/security/src/aclresource.c index 5ed446b..6d20938 100644 --- a/resource/csdk/security/src/aclresource.c +++ b/resource/csdk/security/src/aclresource.c @@ -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); } } } diff --git a/resource/csdk/security/src/policyengine.c b/resource/csdk/security/src/policyengine.c index d77a21f..3747140 100644 --- a/resource/csdk/security/src/policyengine.c +++ b/resource/csdk/security/src/policyengine.c @@ -202,6 +202,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], -- 2.7.4