summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Nash <george.nash@intel.com>2016-12-01 14:31:43 -0800
committerJooseok Park <jooseok.park@samsung.com>2017-06-15 12:23:41 +0900
commite39a0c80f57e5f3a4c857a17de2ec839bdeec7d2 (patch)
tree32594da788a541c2cb6f997716094ceef615f4c3
parentfde73fe2bbb7d0e543aa899c6a78bf3f61caa80a (diff)
downloadiotivity-e39a0c80f57e5f3a4c857a17de2ec839bdeec7d2.tar.gz
iotivity-e39a0c80f57e5f3a4c857a17de2ec839bdeec7d2.tar.bz2
iotivity-e39a0c80f57e5f3a4c857a17de2ec839bdeec7d2.zip
[IOT-1643] Fix illegal memory access - Don't return local string
the std::string ret is a local varaible and is destroyed when the what() member function returns. Put the return string into the m_whatMessage variable. Since 'what()' member function is a const function it can not modify the member variable m_whatMessage so it is generated in the ResourceInitException constructor. Issue found using static analysis tool. Change-Id: I907b984f35dee59b2f300afe6a640b15a26f020f Signed-off-by: George Nash <george.nash@intel.com> Reviewed-on: https://gerrit.iotivity.org/gerrit/15035 Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org> Reviewed-by: Larry Sachs <larry.j.sachs@intel.com> Reviewed-by: Habib Virji <habib.virji@samsung.com> Reviewed-by: Dan Mihai <Daniel.Mihai@microsoft.com>
-rw-r--r--resource/include/ResourceInitException.h70
1 files changed, 35 insertions, 35 deletions
diff --git a/resource/include/ResourceInitException.h b/resource/include/ResourceInitException.h
index e70073943..b15134a1d 100644
--- a/resource/include/ResourceInitException.h
+++ b/resource/include/ResourceInitException.h
@@ -36,15 +36,47 @@ namespace OC
bool missingClientWrapper,
bool invalidPort,
bool invalidIp)
- : m_missingUri(missingUri),
+ : m_whatMessage(),
+ m_missingUri(missingUri),
m_missingType(missingType),
m_missingInterface(missingInterface),
m_missingClientWrapper(missingClientWrapper),
m_invalidPort(invalidPort),
m_invalidIp(invalidIp)
{
+ if(isUriMissing())
+ {
+ m_whatMessage += OC::InitException::MISSING_URI;
+ }
+
+ if(isTypeMissing())
+ {
+ m_whatMessage += OC::InitException::MISSING_TYPE;
+ }
+
+ if(isInterfaceMissing())
+ {
+ m_whatMessage += OC::InitException::MISSING_INTERFACE;
+ }
+
+ if(isClientWrapperMissing())
+ {
+ m_whatMessage += OC::InitException::MISSING_CLIENT_WRAPPER;
+ }
+
+ if(isInvalidPort())
+ {
+ m_whatMessage += OC::InitException::INVALID_PORT;
+ }
+
+ if(isInvalidIp())
+ {
+ m_whatMessage += OC::InitException::INVALID_IP;
+ }
}
+ virtual ~ResourceInitException() throw() {}
+
bool isInvalidPort() const
{
return m_invalidPort;
@@ -77,43 +109,11 @@ namespace OC
virtual const char* what() const BOOST_NOEXCEPT
{
- std::string ret;
-
- if(isUriMissing())
- {
- ret += OC::InitException::MISSING_URI;
- }
-
- if(isTypeMissing())
- {
- ret += OC::InitException::MISSING_TYPE;
- }
-
- if(isInterfaceMissing())
- {
- ret += OC::InitException::MISSING_INTERFACE;
- }
-
- if(isClientWrapperMissing())
- {
- ret += OC::InitException::MISSING_CLIENT_WRAPPER;
- }
-
- if(isInvalidPort())
- {
- ret += OC::InitException::INVALID_PORT;
- }
-
- if(isInvalidIp())
- {
- ret += OC::InitException::INVALID_IP;
- }
-
- return ret.c_str();
+ return m_whatMessage.c_str();
}
private:
-
+ std::string m_whatMessage;
bool m_missingUri;
bool m_missingType;
bool m_missingInterface;