Commit 53479c7b authored by Jihun Ha's avatar Jihun Ha Committed by Madan Lanka

Fix defects detected by SVACE system in easy setup

SVACE which is one of static code analysis tools detects several defects
in easy setup. This patch fixes them.

Change-Id: Ie7e3eb692c58c586b6d0964cf6af24829c39eb11
Signed-off-by: default avatarJihun Ha <jihun.ha@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/10021Tested-by: default avatarjenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: default avatarMadan Lanka <lanka.madan@samsung.com>
parent c882261a
......@@ -266,10 +266,17 @@ void updateProvResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input)
void updateWiFiResource(OCRepPayload* input)
{
ESWiFiProvData* wiFiData = (ESWiFiProvData*)OICMalloc(sizeof(ESWiFiProvData));
if(wiFiData == NULL)
{
OIC_LOG(DEBUG, ES_RH_TAG, "OICMalloc is failed");
return ;
}
memset(wiFiData->ssid, 0, MAX_SSIDLEN);
memset(wiFiData->pwd, 0, MAX_CREDLEN);
wiFiData->authtype = NONE_AUTH;
wiFiData->enctype = NONE_AUTH;
wiFiData->userdata = NULL;
char* ssid = NULL;
......@@ -330,10 +337,16 @@ void updateWiFiResource(OCRepPayload* input)
void updateCloudResource(OCRepPayload* input)
{
ESCloudProvData* cloudData = (ESCloudProvData*)OICMalloc(sizeof(ESCloudProvData));
if(cloudData == NULL)
{
OIC_LOG(DEBUG, ES_RH_TAG, "OICMalloc is failed");
return;
}
memset(cloudData->authCode, 0, OIC_STRING_MAX_VALUE);
memset(cloudData->authProvider, 0, OIC_STRING_MAX_VALUE);
memset(cloudData->ciServer, 0, OIC_STRING_MAX_VALUE);
cloudData->userdata = NULL;
char *authCode = NULL;
......@@ -386,10 +399,14 @@ void updateCloudResource(OCRepPayload* input)
void updateDevConfResource(OCRepPayload* input)
{
ESDevConfProvData* devConfData = (ESDevConfProvData*)OICMalloc(sizeof(ESDevConfProvData));
if(devConfData == NULL)
{
OIC_LOG(DEBUG, ES_RH_TAG, "OICMalloc is failed");
return;
}
memset(devConfData->language, 0, OIC_STRING_MAX_VALUE);
memset(devConfData->country, 0, OIC_STRING_MAX_VALUE);
devConfData->userdata = NULL;
char *country = NULL;
......@@ -446,7 +463,9 @@ OCRepPayload* constructResponseOfWiFi()
size_t dimensions[MAX_REP_ARRAY_DEPTH] = {gWiFiResource.numMode, 0, 0};
int64_t *modes_64 = (int64_t *)OICMalloc(gWiFiResource.numMode * sizeof(int64_t));
for(int i = 0 ; i < gWiFiResource.numMode ; ++i)
{
modes_64[i] = gWiFiResource.supportedMode[i];
}
OCRepPayloadSetIntArray(payload, OC_RSRVD_ES_SUPPORTEDWIFIMODE, (int64_t *)modes_64, dimensions);
OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_SUPPORTEDWIFIFREQ, gWiFiResource.supportedFreq);
......@@ -536,14 +555,22 @@ OCRepPayload* constructResponseOfProv(OCEntityHandlerRequest *ehRequest)
payload->next = constructResponseOfWiFi();
if(payload->next)
{
payload->next->next = constructResponseOfCloud();
}
else
{
return payload;
}
if(payload->next->next)
{
payload->next->next->next = constructResponseOfDevConf();
}
else
{
return payload;
}
}
}
......
......@@ -49,9 +49,12 @@ public:
MockRepository mocks;
protected:
virtual ~TestWithMock() noexcept(noexcept(std::declval<Test>().~Test())) {}
virtual ~TestWithMock() noexcept(noexcept(std::declval<Test>().~Test()))
{
}
virtual void TearDown() {
virtual void TearDown()
{
try
{
mocks.VerifyAll();
......@@ -303,9 +306,12 @@ TEST_F(EasysetupEnrolleeTest, ProvisioningPropertiesIsWellConstructedInResponseP
{
EnrolleeStatus enrolleeStatus = status->getEnrolleeStatus();
if(enrolleeStatus.getProvStatus() == ES_STATE_CONNECTED_TO_ENROLLER &&
enrolleeStatus.getLastErrCode() == ES_ERRCODE_NO_INTERNETCONNECTION)
{
isWellConstructed = true;
}
}
});
ESResult ret = startEnrollee();
......@@ -341,14 +347,18 @@ TEST_F(EasysetupEnrolleeTest, WiFiAndDevConfProperiesProvisionedWithSuccess)
!strcmp(data->pwd, "Iotivity_PWD") &&
data->authtype == WPA2_PSK &&
data->enctype == TKIP_AES)
{
cntForReceivedCallbackWithSuccess++;
}
});
mocks.OnCallFunc(DevConfProvCbInApp).Do(
[& cntForReceivedCallbackWithSuccess](ESDevConfProvData *data)
{
if(!strcmp(data->language, "korean") &&
!strcmp(data->country, "Korea"))
{
cntForReceivedCallbackWithSuccess++;
}
});
startEnrollee();
......@@ -372,7 +382,9 @@ TEST_F(EasysetupEnrolleeTest, CloudServerProperiesProvisionedWithSuccess)
{
// Will called twice
if(status->getESResult() == ES_OK)
{
cntForReceivedCallbackWithSuccess++;
}
});
mocks.OnCallFunc(CloudDataCbInApp).Do(
......@@ -381,7 +393,9 @@ TEST_F(EasysetupEnrolleeTest, CloudServerProperiesProvisionedWithSuccess)
if(!strcmp(data->authCode, "authCode") &&
!strcmp(data->authProvider, "authProvider") &&
!strcmp(data->ciServer, "ciServer"))
{
cntForReceivedCallbackWithSuccess++;
}
});
startEnrollee();
......
......@@ -48,9 +48,11 @@ private:
public:
ESMediatorSimulator()
: m_remoteEnrollee(), m_discoveryCb(), m_getConfigurationCb(), m_getStatusCb(),
m_DevicePropProvisioningCb(), m_CloudPropProvisioningCb() { };
m_DevicePropProvisioningCb(), m_CloudPropProvisioningCb()
{
};
~ESMediatorSimulator() = default;
ESMediatorSimulator(const ESMediatorSimulator &) = delete;
ESMediatorSimulator & operator = (const ESMediatorSimulator &) = delete;
......@@ -65,7 +67,7 @@ public:
OCConnectivityType::CT_DEFAULT,
std::bind(&ESMediatorSimulator::discoverRemoteEnrolleeCb,
this, std::placeholders::_1));
}
void getConfiguration(std::function<void(std::shared_ptr< GetConfigurationStatus >)> cb)
......@@ -76,7 +78,7 @@ public:
OC::OCPlatform::findResource("", uri,
OCConnectivityType::CT_DEFAULT,
std::bind(&ESMediatorSimulator::discoverRemoteEnrolleeCbToGetConfiguration,
this, std::placeholders::_1));
this, std::placeholders::_1));
}
void getStatus(std::function<void(std::shared_ptr< GetEnrolleeStatus >)> cb)
......@@ -87,7 +89,7 @@ public:
OC::OCPlatform::findResource("", uri,
OCConnectivityType::CT_DEFAULT,
std::bind(&ESMediatorSimulator::discoverRemoteEnrolleeCbToGetStatus,
this, std::placeholders::_1));
this, std::placeholders::_1));
}
void provisionDeviceProperties(std::function<void(std::shared_ptr< DevicePropProvisioningStatus >)> cb)
......@@ -98,7 +100,7 @@ public:
OC::OCPlatform::findResource("", uri,
OCConnectivityType::CT_DEFAULT,
std::bind(&ESMediatorSimulator::discoverRemoteEnrolleeCbToProvisionDeviceProperties,
this, std::placeholders::_1));
this, std::placeholders::_1));
}
void provisionCloudProperties(std::function<void(std::shared_ptr< CloudPropProvisioningStatus >)> cb)
......@@ -109,7 +111,7 @@ public:
OC::OCPlatform::findResource("", uri,
OCConnectivityType::CT_DEFAULT,
std::bind(&ESMediatorSimulator::discoverRemoteEnrolleeCbToProvisionCloudProperties,
this, std::placeholders::_1));
this, std::placeholders::_1));
}
private:
......@@ -121,19 +123,19 @@ private:
m_discoveryCb(resource);
m_discoveryCb = NULL;
}
}
}
void getConfigurationCallback(std::shared_ptr< GetConfigurationStatus > getConfigurationStatus)
{
if(m_getConfigurationCb != NULL)
{
m_getConfigurationCb(getConfigurationStatus);
m_getConfigurationCb = NULL;
m_getConfigurationCb = NULL;
}
}
void discoverRemoteEnrolleeCbToGetConfiguration(std::shared_ptr<OC::OCResource> resource)
{
{
if(!resource->getResourceTypes().at(0).compare(PROV_RESOURCE_TYPE) && m_getConfigurationCb
&& !m_remoteEnrollee)
{
......@@ -142,7 +144,7 @@ private:
if(m_remoteEnrollee != NULL)
{
m_remoteEnrollee->getConfiguration(std::bind(
&ESMediatorSimulator::getConfigurationCallback, this, std::placeholders::_1));
&ESMediatorSimulator::getConfigurationCallback, this, std::placeholders::_1));
}
}
}
......@@ -166,7 +168,7 @@ private:
if(m_remoteEnrollee != NULL)
{
m_remoteEnrollee->getStatus(std::bind(
&ESMediatorSimulator::getStatusCallback, this, std::placeholders::_1));
&ESMediatorSimulator::getStatusCallback, this, std::placeholders::_1));
}
}
}
......@@ -193,9 +195,9 @@ private:
DeviceProp devProp;
devProp.setWiFiProp("Iotivity_SSID", "Iotivity_PWD", WPA2_PSK, TKIP_AES);
devProp.setDevConfProp("korean", "Korea");
m_remoteEnrollee->provisionDeviceProperties(devProp,
std::bind(&ESMediatorSimulator::deviceProvisioningStatusCallback,
m_remoteEnrollee->provisionDeviceProperties(devProp,
std::bind(&ESMediatorSimulator::deviceProvisioningStatusCallback,
this, std::placeholders::_1));
}
}
......@@ -203,29 +205,31 @@ private:
void cloudProvisioningStatusCallback(std::shared_ptr< CloudPropProvisioningStatus >
cloudPropProvisioningStatus)
{
{
if(m_CloudPropProvisioningCb != NULL)
{
m_CloudPropProvisioningCb(cloudPropProvisioningStatus);
if(cloudPropProvisioningStatus->getESCloudState() == ES_CLOUD_PROVISIONING_SUCCESS)
if(cloudPropProvisioningStatus->getESCloudState() == ES_CLOUD_PROVISIONING_SUCCESS)
{
m_CloudPropProvisioningCb = NULL;
}
}
}
void discoverRemoteEnrolleeCbToProvisionCloudProperties(std::shared_ptr<OC::OCResource> resource)
{
{
if(!resource->getResourceTypes().at(0).compare(PROV_RESOURCE_TYPE) &&
m_CloudPropProvisioningCb && !m_remoteEnrollee)
{
m_remoteEnrollee = EasySetup::getInstance()->createRemoteEnrollee(resource);
if(m_remoteEnrollee != NULL)
{
{
CloudProp cloudProp;
cloudProp.setCloudProp("authCode", "authProvider", "ciServer");
m_remoteEnrollee->provisionCloudProperties(cloudProp,
std::bind(&ESMediatorSimulator::cloudProvisioningStatusCallback,
m_remoteEnrollee->provisionCloudProperties(cloudProp,
std::bind(&ESMediatorSimulator::cloudProvisioningStatusCallback,
this, std::placeholders::_1));
}
}
......
......@@ -53,7 +53,10 @@ namespace OIC
/**
* Constructor
*/
EnrolleeStatus(const OCRepresentation& rep) { m_rep = rep; }
EnrolleeStatus(const OCRepresentation& rep)
{
m_rep = rep;
}
EnrolleeStatus(const EnrolleeStatus& enrolleeStatus) :
m_rep(enrolleeStatus.getRepresentation())
......@@ -73,8 +76,10 @@ namespace OIC
ProvStatus getProvStatus()
{
if(m_rep.hasAttribute(OC_RSRVD_ES_PROVSTATUS))
{
return static_cast<ProvStatus>(
m_rep.getValue<int>(OC_RSRVD_ES_PROVSTATUS));
}
return ES_STATE_INIT;
}
......@@ -86,8 +91,10 @@ namespace OIC
ESErrorCode getLastErrCode()
{
if(m_rep.hasAttribute(OC_RSRVD_ES_LAST_ERRORCODE))
{
return static_cast<ESErrorCode>(
m_rep.getValue<int>(OC_RSRVD_ES_LAST_ERRORCODE));
}
return ES_ERRCODE_NO_ERROR;
}
......@@ -114,7 +121,9 @@ namespace OIC
/**
* Constructor
*/
CloudProp() {};
CloudProp()
{
};
/**
* Constructor with OCRepresentation object. This is used for JNI communication.
......@@ -157,7 +166,9 @@ namespace OIC
std::string getAuthCode()
{
if(m_rep.hasAttribute(OC_RSRVD_ES_AUTHCODE))
{
return m_rep.getValue<std::string>(OC_RSRVD_ES_AUTHCODE);
}
return std::string("");
}
......@@ -169,7 +180,9 @@ namespace OIC
std::string getAuthProvider()
{
if(m_rep.hasAttribute(OC_RSRVD_ES_AUTHPROVIDER))
{
return m_rep.getValue<std::string>(OC_RSRVD_ES_AUTHPROVIDER);
}
return std::string("");
}
......@@ -181,7 +194,9 @@ namespace OIC
std::string getCiServer()
{
if(m_rep.hasAttribute(OC_RSRVD_ES_CISERVER))
{
return m_rep.getValue<std::string>(OC_RSRVD_ES_CISERVER);
}
return std::string("");
}
......@@ -225,7 +240,10 @@ namespace OIC
/**
* Constructor with OCRepresentation object. This is used for JNI communication.
*/
DeviceProp(const OCRepresentation &rep) { m_rep = rep; }
DeviceProp(const OCRepresentation &rep)
{
m_rep = rep;
}
/**
* Set WiFi resource properties to be delivered to Enrollee
......@@ -266,7 +284,9 @@ namespace OIC
std::string getSsid()
{
if(m_rep.hasAttribute(OC_RSRVD_ES_SSID))
{
return m_rep.getValue<std::string>(OC_RSRVD_ES_SSID);
}
return std::string("");
}
......@@ -278,7 +298,9 @@ namespace OIC
std::string getPassword()
{
if(m_rep.hasAttribute(OC_RSRVD_ES_CRED))
{
return m_rep.getValue<std::string>(OC_RSRVD_ES_CRED);
}
return std::string("");
}
......@@ -292,7 +314,9 @@ namespace OIC
WIFI_AUTHTYPE getAuthType()
{
if(m_rep.hasAttribute(OC_RSRVD_ES_AUTHTYPE))
{
return static_cast<WIFI_AUTHTYPE>(m_rep.getValue<int>(OC_RSRVD_ES_AUTHTYPE));
}
return NONE_AUTH;
}
......@@ -306,7 +330,9 @@ namespace OIC
WIFI_ENCTYPE getEncType()
{
if(m_rep.hasAttribute(OC_RSRVD_ES_ENCTYPE))
{
return static_cast<WIFI_ENCTYPE>(m_rep.getValue<int>(OC_RSRVD_ES_ENCTYPE));
}
return NONE_ENC;
}
......@@ -319,7 +345,9 @@ namespace OIC
std::string getLanguage()
{
if(m_rep.hasAttribute(OC_RSRVD_ES_LANGUAGE))
{
return m_rep.getValue<std::string>(OC_RSRVD_ES_LANGUAGE);
}
return std::string("");
}
......@@ -332,7 +360,9 @@ namespace OIC
std::string getCountry()
{
if(m_rep.hasAttribute(OC_RSRVD_ES_COUNTRY))
{
return m_rep.getValue<std::string>(OC_RSRVD_ES_COUNTRY);
}
return std::string("");
}
......
......@@ -160,7 +160,8 @@ namespace OIC
OC::OCRepresentation rep;
std::function< OCStackResult(void) > getStatus = [&]
{ return m_ocResource->get(m_ocResource->getResourceTypes().at(0),
{
return m_ocResource->get(m_ocResource->getResourceTypes().at(0),
DEFAULT_INTERFACE, query, std::function<void(const HeaderOptions& headerOptions,
const OCRepresentation& rep, const int eCode) >(
std::bind(&EnrolleeResource::onGetStatusResponse, this,
......@@ -193,7 +194,8 @@ namespace OIC
OC::OCRepresentation rep;
std::function< OCStackResult(void) > getConfigurationStatus = [&]
{ return m_ocResource->get(m_ocResource->getResourceTypes().at(0),
{
return m_ocResource->get(m_ocResource->getResourceTypes().at(0),
BATCH_INTERFACE, query, std::function<void(const HeaderOptions& headerOptions,
const OCRepresentation& rep, const int eCode) >(
std::bind(&EnrolleeResource::onGetConfigurationResponse, this,
......
......@@ -101,7 +101,7 @@ namespace OIC
{
size_t outBufSize = B64DECODE_OUT_SAFESIZE((uuidString.length() + 1));
uint8_t* outKey = (uint8_t*)OICCalloc(1, outBufSize);
uint32_t outKeySize;
uint32_t outKeySize = 0;
if(NULL == outKey)
{
OIC_LOG (ERROR, ENROLEE_SECURITY_TAG, "Failed to memoray allocation.");
......@@ -165,7 +165,7 @@ namespace OIC
pOwnedDevList.clear();
pUnownedDevList.clear();
OCStackResult result;
OCStackResult result = OC_STACK_ERROR;
result = OCSecure::discoverOwnedDevices(ES_SEC_DISCOVERY_TIMEOUT,
pOwnedDevList);
......@@ -346,7 +346,7 @@ namespace OIC
char href[] = "*";
size_t len = strlen(href)+1; // '1' for null termination
rsrc->href = (char*) OICCalloc(len, sizeof(char));
if(!rsrc)
if(!rsrc->href)
{
OIC_LOG(DEBUG, ENROLEE_SECURITY_TAG, "createAcl: OICCalloc error return");
OCDeleteACLList(acl);
......@@ -354,7 +354,7 @@ namespace OIC
}
OICStrcpy(rsrc->href, len, href);
int arrLen = 1;
size_t arrLen = 1;
rsrc->typeLen = arrLen;
rsrc->types = (char**)OICCalloc(arrLen, sizeof(char*));
rsrc->interfaces = (char**)OICCalloc(arrLen, sizeof(char*));
......
......@@ -53,7 +53,9 @@ void ReadUserdataCb(OCRepPayload* payload, char* resourceType, void** userdata)
if (OCRepPayloadGetPropInt(payload, USERPROPERTY_KEY_INT, &value))
{
if(*userdata != NULL)
{
*userdata = (void*)OICMalloc(sizeof(UserProperties));
}
OIC_LOG_V(INFO, ESX_ENROLLEE_TAG, "[User specific property] %s : %ld",
USERPROPERTY_KEY_INT, value);
((UserProperties*)(*userdata))->userValue_int = value;
......
......@@ -66,48 +66,16 @@ void WiFiProvCbInApp(ESWiFiProvData *eventData)
{
printf("WiFiProvCbInApp IN\n");
if(eventData->ssid != NULL)
if(eventData == NULL)
{
printf("SSID : %s\n", eventData->ssid);
}
else
{
printf("ERROR! SSID IS NULL\n");
return;
}
if(eventData->pwd != NULL)
{
printf("Password : %s\n", eventData->pwd);
}
else
{
printf("ERROR! Password IS NULL\n");
return;
}
if(eventData->authtype == NONE_AUTH || eventData->authtype == WEP || \
eventData->authtype == WPA_PSK || eventData->authtype == WPA2_PSK)
{
printf("AuthType : %d\n", eventData->authtype);
}
else
{
printf("ERROR! AuthType IS NULL\n");
return;
printf("ESWiFiProvData is NULL\n");
return ;
}
if(eventData->enctype == NONE_ENC || eventData->enctype == WEP_64 || \
eventData->enctype == WEP_128 || eventData->enctype == TKIP || \
eventData->enctype == AES || eventData->enctype == TKIP_AES)
{
printf("EncType : %d\n", eventData->enctype);
}
else
{
printf("ERROR! EncType IS NULL\n");
return;
}
printf("SSID : %s\n", eventData->ssid);
printf("Password : %s\n", eventData->pwd);
printf("AuthType : %d\n", eventData->authtype);
printf("EncType : %d\n", eventData->enctype);
if(eventData->userdata != NULL)
{
......@@ -121,25 +89,14 @@ void DevConfProvCbInApp(ESDevConfProvData *eventData)
{
printf("DevConfProvCbInApp IN\n");
if(eventData->language != NULL)
{
printf("Language : %s\n", eventData->language);
}
else
if(eventData == NULL)
{
printf("ERROR! Language IS NULL\n");
return;
printf("ESDevConfProvData is NULL\n");
return ;
}
if(eventData->country != NULL)
{
printf("Country : %s\n", eventData->country);
}
else
{
printf("ERROR! Country IS NULL\n");
return;
}
printf("Language : %s\n", eventData->language);
printf("Country : %s\n", eventData->country);
printf("DevConfProvCbInApp OUT\n");
}
......@@ -148,35 +105,15 @@ void CloudDataProvCbInApp(ESCloudProvData *eventData)
{
printf("CloudDataProvCbInApp IN\n");
if(eventData->authCode != NULL)
{
printf("AuthCode : %s\n", eventData->authCode);
}
else
{
printf("ERROR! AuthCode IS NULL\n");
return;
}
if(eventData->authProvider != NULL)
{
printf("AuthProvider : %s\n", eventData->authProvider);
}
else
if(eventData == NULL)
{
printf("ERROR! AuthProvider IS NULL\n");
return;
printf("ESCloudProvData is NULL\n");
return ;
}
if(eventData->ciServer != NULL)
{
printf("CI Server : %s\n", eventData->ciServer);
}
else
{
printf("ERROR! CI Server IS NULL\n");
return;
}
printf("AuthCode : %s\n", eventData->authCode);
printf("AuthProvider : %s\n", eventData->authProvider);