[IOT-1550] Resolved reset issue on rowner of cred
authorjs126.lee <js126.lee@samsung.com>
Tue, 15 Nov 2016 04:48:08 +0000 (13:48 +0900)
committerRandeep Singh <randeep.s@samsung.com>
Thu, 17 Nov 2016 10:21:58 +0000 (10:21 +0000)
https://jira.iotivity.org/browse/IOT-1550

issue : Rowner of cred is reset, when saving Cert. chain
        using SRPSaveTrustCertChain and SRPSaveOwnCertChain.

Patch 1: upload patch
Patch 2: rebase
Patch 3: Apply review comment

Change-Id: I59cdbfb30253c61e1c27dcf640958899af976a96
Signed-off-by: js126.lee <js126.lee@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/14327
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Chul Lee <chuls.lee@samsung.com>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
Reviewed-by: Randeep Singh <randeep.s@samsung.com>
(cherry picked from commit 39f4a884082aa687f86fc24296b37401780dc9cb)
Reviewed-on: https://gerrit.iotivity.org/gerrit/14441

resource/csdk/security/src/credresource.c
resource/provisioning/examples/cloudClient.cpp
resource/provisioning/examples/provisioningclient.cpp

index 2d327d3..65cbe65 100644 (file)
@@ -1519,7 +1519,7 @@ OCStackResult AddCredential(OicSecCred_t * newCred)
 
     //the newCred is not valid if it is empty
 
-    if (memcmp(&(newCred->subject.id), &emptyOwner, UUID_IDENTITY_SIZE) == 0)
+    if (memcmp(&(newCred->subject), &emptyOwner, sizeof(OicUuid_t)) == 0)
     {
         validFlag = false;
     }
@@ -1553,8 +1553,10 @@ OCStackResult AddCredential(OicSecCred_t * newCred)
     {
         LL_APPEND(gCred, newCred);
     }
-
-    memcpy(&(gCred->rownerID), &(newCred->rownerID), sizeof(OicUuid_t));
+    if (memcmp(&(newCred->rownerID), &emptyOwner, sizeof(OicUuid_t)) != 0)
+    {
+        memcpy(&(gCred->rownerID), &(newCred->rownerID), sizeof(OicUuid_t));
+    }
     if (UpdatePersistentStorage(gCred))
     {
         ret = OC_STACK_OK;
index a546bed..3d67d2d 100644 (file)
@@ -229,11 +229,11 @@ static int saveTrustCert(void)
         size_t fsize;
         if (fseeko(fp, 0, SEEK_END) == 0 && (fsize = ftello(fp)) > 0)
         {
-            trustCertChainArray.data = (uint8_t*)OICCalloc(1, fsize+1);
-            trustCertChainArray.len = fsize+1;
+            trustCertChainArray.data = (uint8_t*)OICCalloc(1, fsize);
+            trustCertChainArray.len = fsize;
             if (NULL == trustCertChainArray.data)
             {
-                OIC_LOG(ERROR,TAG,"OICCalloc");
+                OIC_LOG(ERROR,TAG,"Failed to allocate memory");
                 fclose(fp);
                 return res;
             }
index 53e9c10..a5d3fc4 100644 (file)
@@ -817,11 +817,11 @@ static int saveTrustCert(void)
         size_t fsize;
         if (fseeko(fp, 0, SEEK_END) == 0 && (fsize = ftello(fp)) >= 0)
         {
-            trustCertChainArray.data = (uint8_t*)OICMalloc(fsize);
+            trustCertChainArray.data = (uint8_t*)OICCalloc(1, fsize);
             trustCertChainArray.len = fsize;
             if (NULL == trustCertChainArray.data)
             {
-                OIC_LOG(ERROR,TAG,"malloc");
+                OIC_LOG(ERROR,TAG,"Failed to allocate memory");
                 fclose(fp);
                 return -1;
             }