From 42a7bac48439510e8b4870686bc1feea4d028040 Mon Sep 17 00:00:00 2001
From: "ol.beketov"
Date: Sun, 21 May 2017 12:37:48 +0300
Subject: [PATCH] [IOT-2087] Check NULL pointer after realloc
Change-Id: Ia9eac5375ea4d322cbe4f685588a57b6af047deb
Signed-off-by: ol.beketov
Reviewed-on: https://gerrit.iotivity.org/gerrit/19621
Tested-by: jenkins-iotivity
Reviewed-by: Oleksandr Dmytrenko
Reviewed-by: Dmitriy Zhuravlev
---
bridging/plugins/hue_plugin/hue_resource.cpp | 28 ++++++++++++++++++++++++++--
1 file changed, 26 insertions(+), 2 deletions(-)
diff --git a/bridging/plugins/hue_plugin/hue_resource.cpp b/bridging/plugins/hue_plugin/hue_resource.cpp
index 657d6a9..af7e823 100644
--- a/bridging/plugins/hue_plugin/hue_resource.cpp
+++ b/bridging/plugins/hue_plugin/hue_resource.cpp
@@ -259,12 +259,24 @@ void addAuthorizedBridgeCB(const char *macAddress, const char *ClientId)
{
uint32_t prefix_size = MAX_QUERY_STRING;
char *prefix = (char *) OICMalloc(prefix_size);
+ if (NULL == prefix)
+ {
+ OIC_LOG_V(INFO, TAG, " Failed to malloc prefix");
+ return;
+ }
/*get prefix for discovering lights*/
result = hueAuthGetHttpPrefix(prefix, &prefix_size, macAddress, ClientId);
if (result == MPM_RESULT_INSUFFICIENT_BUFFER)
{
- prefix = (char *) realloc(prefix, prefix_size);
+ char *tmp = (char *) OICRealloc(prefix, prefix_size);
+ if (NULL == tmp)
+ {
+ OIC_LOG_V(INFO, TAG, " Failed to realloc prefix");
+ OICFree(prefix);
+ return;
+ }
+ prefix = tmp;
result = hueAuthGetHttpPrefix(prefix, &prefix_size, macAddress, ClientId);
}
if (result == MPM_RESULT_OK)
@@ -570,11 +582,23 @@ MPMResult pluginReconnect(MPMPluginCtx *, MPMPipeMessage *message)
}
uint32_t prefix_size = MAX_QUERY_STRING;
char *prefix = (char *) OICMalloc(prefix_size);
+ if (NULL == prefix)
+ {
+ OIC_LOG_V(INFO, TAG, " Failed to malloc prefix");
+ return MPM_RESULT_INTERNAL_ERROR;
+ }
result = hueAuthGetHttpPrefix(prefix, &prefix_size, plugindetails->bridgeMac,
plugindetails->clientId);
if (result == MPM_RESULT_INSUFFICIENT_BUFFER)
{
- prefix = (char *) realloc(prefix, prefix_size);
+ char *tmp = (char *) OICRealloc(prefix, prefix_size);
+ if (NULL == tmp)
+ {
+ OIC_LOG(DEBUG, TAG, "Failed to realloc prefix");
+ OICFree(prefix);
+ return MPM_RESULT_INTERNAL_ERROR;
+ }
+ prefix = tmp;
result = hueAuthGetHttpPrefix(prefix, &prefix_size, plugindetails->bridgeMac,
plugindetails->clientId);
}
--
2.7.4