From: Jihun Ha Date: Tue, 31 Jan 2017 06:34:10 +0000 (+0900) Subject: Fix a defect to access a NULL variable X-Git-Tag: 1.3.0~736 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4d6ad940e542511c7acd41f78ce231a23fb1567a;p=platform%2Fupstream%2Fiotivity.git Fix a defect to access a NULL variable If OICMalloc fails, mediatorDevId gets to be NULL, which causes a crash in calling getDeviceID API with mediatorDevId. Change-Id: Ie59211187e6be896f0f4d0387884092812521a84 Signed-off-by: Jihun Ha Reviewed-on: https://gerrit.iotivity.org/gerrit/16905 Tested-by: jenkins-iotivity Reviewed-by: Heewon Park Reviewed-by: Uze Choi --- diff --git a/service/easy-setup/mediator/richsdk/src/EnrolleeSecurity.cpp b/service/easy-setup/mediator/richsdk/src/EnrolleeSecurity.cpp index 0034cef..33ce322 100755 --- a/service/easy-setup/mediator/richsdk/src/EnrolleeSecurity.cpp +++ b/service/easy-setup/mediator/richsdk/src/EnrolleeSecurity.cpp @@ -67,32 +67,6 @@ namespace OIC { (void) secDbPath; m_ocResource = resource; - - OCUUIdentity* mediatorDevId = (OCUUIdentity* )OICMalloc(sizeof(OCUUIdentity)); - - if(!mediatorDevId) - { - OIC_LOG(ERROR, ENROLEE_SECURITY_TAG, "provisionOwnership: OICMalloc error return"); - m_mediatorID = {}; - } - - if(OC::OCPlatform::getDeviceId(mediatorDevId) != OC_STACK_OK) - { - OIC_LOG(ERROR, ENROLEE_SECURITY_TAG, "getDeviceId is failed."); - OICFree(mediatorDevId); - m_mediatorID = {}; - } - - char uuidString[UUID_STRING_SIZE]; - if(OCConvertUuidToString(mediatorDevId->id, uuidString)) - { - m_mediatorID = uuidString; - } - else - { - m_mediatorID = {}; - } - OIC_LOG_V(DEBUG, ENROLEE_SECURITY_TAG, "EnrolleeSecurity: Mediator ID %s", m_mediatorID.c_str()); } void EnrolleeSecurity::onEnrolleeSecuritySafetyCB(OC::PMResultList_t *result, @@ -447,10 +421,39 @@ namespace OIC OCStackResult result = OC_STACK_ERROR; ESOwnershipTransferData ownershipTransferData; + OCUUIdentity* mediatorDevId = (OCUUIdentity* )OICMalloc(sizeof(OCUUIdentity)); + + if(!mediatorDevId) + { + OIC_LOG(ERROR, ENROLEE_SECURITY_TAG, "provisionOwnership: OICMalloc error return"); + return res; + } + + if(OC::OCPlatform::getDeviceId(mediatorDevId) != OC_STACK_OK) + { + OIC_LOG(ERROR, ENROLEE_SECURITY_TAG, "getDeviceId is failed."); + OICFree(mediatorDevId); + return res; + } + + char uuidString[UUID_STRING_SIZE]; + if(OCConvertUuidToString(mediatorDevId->id, uuidString)) + { + m_mediatorID = uuidString; + OIC_LOG_V(DEBUG, ENROLEE_SECURITY_TAG, "Mediator UUID : %s", uuidString); + OICFree(mediatorDevId); + } + else + { + OIC_LOG(ERROR, ENROLEE_SECURITY_TAG, "OCConvertUuidToString is failed."); + OICFree(mediatorDevId); + return res; + } + OicUuid_t uuid; if(OC_STACK_OK != ConvertStrToUuid(m_ocResource->sid().c_str(), &uuid)) { - OIC_LOG(DEBUG, ENROLEE_SECURITY_TAG, "Convert to uuid from deviceID failed."); + OIC_LOG(ERROR, ENROLEE_SECURITY_TAG, "Convert to uuid from deviceID failed."); return res; }