From 9b61e237ecac81d164cc65f634ebff45fe6ca6de Mon Sep 17 00:00:00 2001 From: Parkhi Date: Thu, 15 Dec 2016 11:10:11 +0900 Subject: [PATCH] Fix defects detected by static analysis Change-Id: Ie07051e70f2b78fc9cdca6e1c1c0d59d7e5bc231 Signed-off-by: Parkhi Reviewed-on: https://gerrit.iotivity.org/gerrit/15465 Tested-by: jenkins-iotivity Reviewed-by: Uze Choi (cherry picked from commit ebce9d66d37228f8a91975d635f9b4c13036ef67) Reviewed-on: https://gerrit.iotivity.org/gerrit/15665 Reviewed-by: Jihun Ha --- .../easy-setup/mediator/richsdk/inc/ESRichCommon.h | 4 +-- .../mediator/richsdk/src/EnrolleeSecurity.cpp | 36 ++++++++++++++++++++-- .../mediator/linux/richsdk_sample/mediator.cpp | 13 +++++--- .../mediator/linux/richsdk_sample/submediator.cpp | 13 +++++--- 4 files changed, 52 insertions(+), 14 deletions(-) diff --git a/service/easy-setup/mediator/richsdk/inc/ESRichCommon.h b/service/easy-setup/mediator/richsdk/inc/ESRichCommon.h index 17eedbe..7c1e8c3 100755 --- a/service/easy-setup/mediator/richsdk/inc/ESRichCommon.h +++ b/service/easy-setup/mediator/richsdk/inc/ESRichCommon.h @@ -77,7 +77,7 @@ namespace OIC * * @return a provisioning status property of Enrollee */ - ProvStatus getProvStatus() + ProvStatus getProvStatus() const { if(m_rep.hasAttribute(OC_RSRVD_ES_PROVSTATUS)) { @@ -92,7 +92,7 @@ namespace OIC * * @return a last error code property of Enrollee. */ - ESErrorCode getLastErrCode() + ESErrorCode getLastErrCode() const { if(m_rep.hasAttribute(OC_RSRVD_ES_LAST_ERRORCODE)) { diff --git a/service/easy-setup/mediator/richsdk/src/EnrolleeSecurity.cpp b/service/easy-setup/mediator/richsdk/src/EnrolleeSecurity.cpp index e20c521..0ed2756 100755 --- a/service/easy-setup/mediator/richsdk/src/EnrolleeSecurity.cpp +++ b/service/easy-setup/mediator/richsdk/src/EnrolleeSecurity.cpp @@ -31,6 +31,7 @@ #include "oic_string.h" #include "utlist.h" #include "srmutility.h" +#include "aclresource.h" #include "internal/doxmresource.h" namespace OIC @@ -807,7 +808,7 @@ namespace OIC { res = ESResult::ES_OK; } - + OCDeleteACLList(acl); return res; } @@ -836,6 +837,7 @@ namespace OIC if(!rsrc) { OIC_LOG(DEBUG, ENROLEE_SECURITY_TAG, "createAcl: OICCalloc error return"); + FreeRsrc(rsrc); OCDeleteACLList(acl); return NULL; } @@ -846,6 +848,7 @@ namespace OIC if(!rsrc->href) { OIC_LOG(DEBUG, ENROLEE_SECURITY_TAG, "createAcl: OICCalloc error return"); + FreeRsrc(rsrc); OCDeleteACLList(acl); return NULL; } @@ -854,10 +857,39 @@ namespace OIC size_t arrLen = 1; rsrc->typeLen = arrLen; rsrc->types = (char**)OICCalloc(arrLen, sizeof(char*)); + if(!rsrc->types) + { + OIC_LOG(DEBUG, ENROLEE_SECURITY_TAG, "createAcl: OICCalloc error return"); + FreeRsrc(rsrc); + OCDeleteACLList(acl); + return NULL; + } + rsrc->types[0] = OICStrdup("rt"); // ignore + if(!rsrc->types[0]) + { + OIC_LOG(DEBUG, ENROLEE_SECURITY_TAG, "createAcl: OICStrdup error return"); + FreeRsrc(rsrc); + OCDeleteACLList(acl); + return NULL; + } + rsrc->interfaceLen = 1; rsrc->interfaces = (char**)OICCalloc(arrLen, sizeof(char*)); - rsrc->types[0] = OICStrdup("rt"); // ignore + if(!rsrc->interfaces) + { + OIC_LOG(DEBUG, ENROLEE_SECURITY_TAG, "createAcl: OICCalloc error return"); + FreeRsrc(rsrc); + OCDeleteACLList(acl); + return NULL; + } rsrc->interfaces[0] = OICStrdup("if"); // ignore + if(!rsrc->interfaces[0]) + { + OIC_LOG(DEBUG, ENROLEE_SECURITY_TAG, "createAcl: OICStrdup error return"); + FreeRsrc(rsrc); + OCDeleteACLList(acl); + return NULL; + } LL_APPEND(ace->resources, rsrc); diff --git a/service/easy-setup/sampleapp/mediator/linux/richsdk_sample/mediator.cpp b/service/easy-setup/sampleapp/mediator/linux/richsdk_sample/mediator.cpp index 41f0a78..32c85cd 100755 --- a/service/easy-setup/sampleapp/mediator/linux/richsdk_sample/mediator.cpp +++ b/service/easy-setup/sampleapp/mediator/linux/richsdk_sample/mediator.cpp @@ -52,12 +52,15 @@ int processUserInput(int min = std::numeric_limits::min(), { assert(min <= max); - int input; + int input = 0; std::cin >> input; std::cin.ignore(std::numeric_limits::max(), '\n'); - if (!std::cin.fail() && min <= input && input <= max) return input; + if (!std::cin.fail() && min <= input && input <= max) + { + return input; + } std::cin.clear(); std::cin.ignore(std::numeric_limits::max(), '\n'); @@ -65,7 +68,7 @@ int processUserInput(int min = std::numeric_limits::min(), throw std::runtime_error("Invalid Input, please try again"); } -void printConfiguration(EnrolleeConf conf) +void printConfiguration(const EnrolleeConf& conf) { cout << "===========================================" << endl; cout << "\tDevice Name : " << conf.getDeviceName() << endl; @@ -81,7 +84,7 @@ void printConfiguration(EnrolleeConf conf) cout << "===========================================" << endl; } -void printStatus(EnrolleeStatus status) +void printStatus(const EnrolleeStatus& status) { cout << "===========================================" << endl; cout << "\tProvStatus : " << status.getProvStatus() << endl; @@ -439,7 +442,7 @@ int main() return -1; } #endif - }catch(OCException& e) + }catch (const std::exception& e) { std::cout << "Exception in main: "<::min(), { assert(min <= max); - int input; + int input = 0; std::cin >> input; std::cin.ignore(std::numeric_limits::max(), '\n'); - if (!std::cin.fail() && min <= input && input <= max) return input; + if (!std::cin.fail() && min <= input && input <= max) + { + return input; + } std::cin.clear(); std::cin.ignore(std::numeric_limits::max(), '\n'); @@ -65,7 +68,7 @@ int processUserInput(int min = std::numeric_limits::min(), throw std::runtime_error("Invalid Input, please try again"); } -void printConfiguration(EnrolleeConf conf) +void printConfiguration(const EnrolleeConf& conf) { cout << "===========================================" << endl; cout << "\tDevice Name : " << conf.getDeviceName() << endl; @@ -81,7 +84,7 @@ void printConfiguration(EnrolleeConf conf) cout << "===========================================" << endl; } -void printStatus(EnrolleeStatus status) +void printStatus(const EnrolleeStatus& status) { cout << "===========================================" << endl; cout << "\tProvStatus : " << status.getProvStatus() << endl; @@ -439,7 +442,7 @@ int main() return -1; } #endif - }catch(OCException& e) + }catch (const std::exception& e) { std::cout << "Exception in main: "<