Resolving svace issues
authoramar <amar.sri@samsung.com>
Thu, 2 Feb 2017 04:54:47 +0000 (13:54 +0900)
committerNathan Heldt-Sheller <nathan.heldt-sheller@intel.com>
Mon, 27 Feb 2017 17:22:46 +0000 (17:22 +0000)
Change-Id: I9086e50f802d93dbacf45858646ddfd828791296
Signed-off-by: Amar Srivastava <amar.sri@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/17043
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Randeep Singh <randeep.s@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/17295
Reviewed-by: Dan Mihai <Daniel.Mihai@microsoft.com>
Reviewed-by: Kevin Kane <kkane@microsoft.com>
Reviewed-by: Nathan Heldt-Sheller <nathan.heldt-sheller@intel.com>
java/jni/JniOcProvisioning.cpp
java/jni/JniOcSecureResource.cpp
resource/csdk/security/src/directpairing.c
resource/csdk/security/src/doxmresource.c
resource/csdk/security/src/pconfresource.c
resource/csdk/security/src/verresource.c

index 3fad9bf..f31e561 100644 (file)
@@ -486,7 +486,7 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcProvisioning_setDisplayPinListen
 #if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
     jbyte* trustCertChainBytes = env->GetByteArrayElements(trustCertChain, 0);
     jsize arrayLength = env->GetArrayLength(trustCertChain);
-    uint16_t credId;
+    uint16_t credId = -1;
     unsigned char* trustedCertChar = new unsigned char[arrayLength];
     try
     {
index 174e618..e399677 100644 (file)
@@ -315,7 +315,7 @@ OCStackResult JniOcSecureResource::provisionDirectPairing(JNIEnv* env, jobjectAr
                 tmp1 = tmp2;
             }
 
-            delete pconf->prm;
+            delete[] pconf->prm;
             delete pconf;
             resultListener->ProvisionResultCallback(result, hasError, ListenerFunc::PROVISIONDIRECTPAIRING);
         };
@@ -333,7 +333,7 @@ OCStackResult JniOcSecureResource::provisionDirectPairing(JNIEnv* env, jobjectAr
             tmp1 = tmp2;
         }
 
-        delete pconf->prm;
+        delete[] pconf->prm;
         delete pconf;
     }
     return ret;
index ad78c10..5b82ad6 100644 (file)
@@ -669,6 +669,8 @@ exit:
             RemoveCredential(&dpairData->peer->deviceID);
             OICFree(dpairData);
             g_dp_proceed_ctx = NULL;
+            OIC_LOG_V(INFO, TAG, "OUT DirectPairingHandler.");
+            return OC_STACK_DELETE_TRANSACTION;
         }
 
         resultCallback(dpairData->userCtx, dpairData->peer, res);
index 9b9b246..7faf347 100644 (file)
@@ -724,7 +724,6 @@ static bool ValidateQuery(const char * query)
     bool bInterfaceQry = false;      // does querystring contains 'if' query ?
     bool bInterfaceMatch = false;    // does 'if' query matches with oic.if.baseline ?
 #ifdef MULTIPLE_OWNER
-    bool bMotQry = false;         // does querystring contains 'mom' and 'owned' query ?
     bool bMotMatch = false;       // does 'mom' query value is not '0' && does query value matches with doxm.owned status?
 #endif //MULTIPLE_OWNER
 
@@ -752,7 +751,6 @@ static bool ValidateQuery(const char * query)
 #ifdef MULTIPLE_OWNER
         if (strncasecmp((char *)parseIter.attrPos, OIC_JSON_MOM_NAME, strlen(OIC_JSON_MOM_NAME)) == 0)
         {
-            bMotQry = true;
             OicSecMomType_t momMode = (OicSecMomType_t)(parseIter.valPos[0] - CHAR_ZERO);
             if(NULL != gDoxm->mom && momMode != gDoxm->mom->mode)
             {
@@ -795,14 +793,8 @@ static bool ValidateQuery(const char * query)
         }
     }
 
-#ifdef MULTIPLE_OWNER
-    return ((bOwnedQry ? bOwnedMatch : true) &&
-            (bDeviceIDQry ? bDeviceIDMatch : true) &&
-            (bMotQry ? bMotMatch : true));
-#else
     return ((bOwnedQry ? bOwnedMatch : true) &&
             (bDeviceIDQry ? bDeviceIDMatch : true));
-#endif //MULTIPLE_OWNER
 }
 
 static OCEntityHandlerResult HandleDoxmGetRequest (const OCEntityHandlerRequest * ehRequest)
@@ -1757,7 +1749,7 @@ OCStackResult InitDoxmResource()
     }
 
     //In case of the server is shut down unintentionally, we should initialize the owner
-    if(false == gDoxm->owned)
+    if(gDoxm && (false == gDoxm->owned))
     {
         OicUuid_t emptyUuid = {.id={0}};
         memcpy(&gDoxm->owner, &emptyUuid, sizeof(OicUuid_t));
@@ -1858,24 +1850,22 @@ OCStackResult SetDoxmDeviceIDSeed(const uint8_t* seed, size_t seedSize)
 
 OCStackResult SetDoxmDeviceID(const OicUuid_t *deviceID)
 {
-    bool isPT = false;
-
-    if(NULL == deviceID)
+    bool isOwnerUpdated = false;
+    bool isRownerUpdated = false;
+    if (NULL == deviceID)
     {
         return OC_STACK_INVALID_PARAM;
     }
-    if(NULL == gDoxm)
+    if (NULL == gDoxm)
     {
         OIC_LOG(ERROR, TAG, "Doxm resource is not initialized.");
         return OC_STACK_NO_RESOURCE;
     }
 
-    //Check the device's OTM state
-
 #ifdef __WITH_DTLS__
     //for normal device.
-    if(true == gDoxm->owned &&
-       memcmp(gDoxm->deviceID.id, gDoxm->owner.id, sizeof(gDoxm->owner.id)) != 0)
+    if (true == gDoxm->owned &&
+        memcmp(gDoxm->deviceID.id, gDoxm->owner.id, sizeof(gDoxm->owner.id)) != 0)
     {
         OIC_LOG(ERROR, TAG, "This device owned by owner's device.");
         OIC_LOG(ERROR, TAG, "Device UUID cannot be changed to guarantee the reliability of the connection.");
@@ -1884,27 +1874,40 @@ OCStackResult SetDoxmDeviceID(const OicUuid_t *deviceID)
 #endif //__WITH_DTLS
 
     //Save the previous UUID
-    OicUuid_t tempUuid;
-    memcpy(tempUuid.id, gDoxm->deviceID.id, sizeof(tempUuid.id));
+    OicUuid_t prevUuid;
+    memcpy(prevUuid.id, gDoxm->deviceID.id, sizeof(prevUuid.id));
 
-    //Change the UUID
+    //Change the device UUID
     memcpy(gDoxm->deviceID.id, deviceID->id, sizeof(deviceID->id));
-    if(isPT)
+
+    //Change the owner ID if necessary
+    if (memcmp(gDoxm->owner.id, prevUuid.id, sizeof(prevUuid.id)) == 0)
     {
         memcpy(gDoxm->owner.id, deviceID->id, sizeof(deviceID->id));
+        isOwnerUpdated = true;
+    }
+    //Change the resource owner ID if necessary
+    if (memcmp(gDoxm->rownerID.id, prevUuid.id, sizeof(prevUuid.id)) == 0)
+    {
         memcpy(gDoxm->rownerID.id, deviceID->id, sizeof(deviceID->id));
+        isRownerUpdated = true;
     }
+    // TODO: T.B.D Change resource owner for pstat, acl and cred
 
     //Update PS
-    if(!UpdatePersistentStorage(gDoxm))
+    if (!UpdatePersistentStorage(gDoxm))
     {
-        //revert UUID in case of update error
-        memcpy(gDoxm->deviceID.id, tempUuid.id, sizeof(tempUuid.id));
-        if(isPT)
+        //revert UUID in case of PSI error
+        memcpy(gDoxm->deviceID.id, prevUuid.id, sizeof(prevUuid.id));
+        if (isOwnerUpdated)
+        {
+            memcpy(gDoxm->owner.id, prevUuid.id, sizeof(prevUuid.id));
+        }
+        if (isRownerUpdated)
         {
-            memcpy(gDoxm->owner.id, tempUuid.id, sizeof(tempUuid.id));
-            memcpy(gDoxm->rownerID.id, tempUuid.id, sizeof(tempUuid.id));
+            memcpy(gDoxm->rownerID.id, prevUuid.id, sizeof(prevUuid.id));
         }
+        // TODO: T.B.D Revert resource owner for pstat, acl and cred
 
         OIC_LOG(ERROR, TAG, "Failed to update persistent storage");
         return OC_STACK_ERROR;
index f30c84f..44758e2 100644 (file)
@@ -817,6 +817,7 @@ static OCEntityHandlerResult HandlePconfGetRequest (const OCEntityHandlerRequest
 {
     uint8_t* payload = NULL;
     size_t size = 0;
+    const OicSecDoxm_t *m_doxm = NULL;
     OCEntityHandlerResult ehRet = OC_EH_OK;
 
     OicSecPconf_t pconf;
@@ -824,7 +825,13 @@ static OCEntityHandlerResult HandlePconfGetRequest (const OCEntityHandlerRequest
 
     OIC_LOG (DEBUG, TAG, "Pconf EntityHandle processing GET request");
 
-    if (true == GetDoxmResourceData()->dpc)
+    m_doxm = GetDoxmResourceData();
+    if (NULL == m_doxm)
+    {
+      OIC_LOG (DEBUG, TAG, "Doxm resource Data is NULL");
+    }
+
+    if ((m_doxm) && (true == m_doxm->dpc))
     {
         //Making response elements for Get request
         if( (true == gPconf->edp) &&
index 4a61953..4159bcc 100644 (file)
@@ -140,6 +140,7 @@ exit:
         OIC_LOG(DEBUG, TAG, "Memory getting reallocated.");
         // reallocate and try again!
         OICFree(outPayload);
+        outPayload = NULL;
         // Since the allocated initial memory failed, double the memory.
         cborLen += cbor_encoder_get_buffer_size(&encoder, encoder.end);
         OIC_LOG_V(DEBUG, TAG, "Ver reallocation size : %zd.", cborLen);