[IOT-2317] gDoxm NULL checks
authorOleksandr Dmytrenko <o.dmytrenko@samsung.com>
Fri, 19 May 2017 11:54:35 +0000 (14:54 +0300)
committerDmitriy Zhuravlev <d.zhuravlev@samsung.com>
Sat, 20 May 2017 06:40:18 +0000 (06:40 +0000)
Accessing global pointer variable gDoxm without NULL check fix

Change-Id: Ief964e6c941ef17a7a24fc07fb4f1807cfc07e0f
Signed-off-by: Oleksandr Dmytrenko <o.dmytrenko@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/20139
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: dongik Lee <dongik.lee@samsung.com>
Reviewed-by: Dmitriy Zhuravlev <d.zhuravlev@samsung.com>
resource/csdk/security/src/doxmresource.c

index b2a24454c28abf99f1fb4604f5c6e85222442e0f..a6898515003fb6c2eb4b096bf85812765b86c040 100644 (file)
@@ -1091,6 +1091,12 @@ void MultipleOwnerDTLSHandshakeCB(const CAEndpoint_t *object,
         CAResult_t caRes = CAGetSecureEndpointData(object, &authenticationSubOwnerInfo);
         if (CA_STATUS_OK == caRes)
         {
+            if (!gDoxm)
+            {
+                OIC_LOG_V(WARNING, TAG, "%s: gDoxm is NULL", __func__);
+                return;
+            }
+
             if (0 == memcmp(authenticationSubOwnerInfo.identity.id, gDoxm->owner.id,
                             authenticationSubOwnerInfo.identity.id_length))
             {
@@ -1260,6 +1266,8 @@ static OCEntityHandlerResult HandleDoxmPostRequest(OCEntityHandlerRequest * ehRe
                 goto exit;
             }
 
+            VERIFY_NOT_NULL(TAG, gDoxm, ERROR);
+
             // in owned state
             if (true == gDoxm->owned)
             {
@@ -1784,9 +1792,13 @@ OCStackResult CreateDoxmResource()
  */
 static OCStackResult CheckDeviceID()
 {
+    OIC_LOG_V(DEBUG, TAG, "IN: %s", __func__);
+
     OCStackResult ret = OC_STACK_ERROR;
     bool validId = false;
 
+    VERIFY_NOT_NULL_RETURN(TAG, gDoxm, ERROR, OC_STACK_INVALID_PARAM);
+
     for (uint8_t i = 0; i < UUID_LENGTH; i++)
     {
         if (gDoxm->deviceID.id[i] != 0)
@@ -1869,6 +1881,8 @@ static OCStackResult CheckDeviceID()
         ret = OC_STACK_OK;
     }
 
+    OIC_LOG_V(DEBUG, TAG, "OUT: %s", __func__);
+
     return ret;
 }
 
@@ -2227,6 +2241,8 @@ OCStackResult SetMOTStatus(bool enable)
 
     OIC_LOG_V(DEBUG, TAG, "In %s", __func__);
 
+    VERIFY_NOT_NULL(TAG, gDoxm, ERROR);
+
     if (NULL == gDoxm->mom && !enable)
     {
         OIC_LOG_V(DEBUG, TAG, "Out %s", __func__);