Fix defect found by static analyzer
authorChaJiWon <jw_wonny.cha@samsung.com>
Fri, 3 Feb 2017 06:04:45 +0000 (15:04 +0900)
committerDan Mihai <Daniel.Mihai@microsoft.com>
Thu, 9 Feb 2017 17:04:32 +0000 (17:04 +0000)
- ocpayloadparse : double free
- occollection : need to NULL check
- ocRepresentation : big size of m_devAddr parameter

Change-Id: I5bd4cbc6d5dab1dfe7293a234e90d2c465a0039c
Signed-off-by: ChaJiWon <jw_wonny.cha@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/17007
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Dan Mihai <Daniel.Mihai@microsoft.com>
resource/csdk/stack/src/occollection.c
resource/csdk/stack/src/ocpayloadparse.c
resource/include/OCRepresentation.h
resource/src/OCRepresentation.cpp

index 6ec6e16..d4198fb 100755 (executable)
@@ -264,6 +264,9 @@ OCStackResult DefaultCollectionEntityHandler(OCEntityHandlerFlag flag, OCEntityH
     {
         ifQueryParam = OICStrdup(OC_RSRVD_INTERFACE_LL);
     }
+
+    VERIFY_PARAM_NON_NULL(TAG, ifQueryParam, "Invalid Parameter ifQueryParam");
+
     if (0 == strcmp(ifQueryParam, OC_RSRVD_INTERFACE_LL) || 0 == strcmp (ifQueryParam, OC_RSRVD_INTERFACE_DEFAULT))
     {
         if (ehRequest->method == OC_REST_PUT || ehRequest->method == OC_REST_POST)
index 2327e46..62a187d 100755 (executable)
@@ -836,6 +836,7 @@ static CborError OCParseSingleRepPayload(OCRepPayload **outPayload, CborValue *o
                 {
                     err = cbor_value_advance(&repMap);
                     free(name);  // Free *TinyCBOR allocated* string.
+                    name = NULL;
                     continue;
                 }
             }
index 309b3e5..541cea5 100644 (file)
@@ -119,7 +119,7 @@ namespace OC
 
             virtual ~OCRepresentation(){}
 
-            void setDevAddr(const OCDevAddr addr);
+            void setDevAddr(const OCDevAddr&);
 
             const std::string getHost() const;
 
index 2997995..edbb756 100644 (file)
@@ -631,7 +631,7 @@ namespace OC
         m_children = children;
     }
 
-    void OCRepresentation::setDevAddr(const OCDevAddr m_devAddr)
+    void OCRepresentation::setDevAddr(const OCDevAddr& m_devAddr)
     {
         std::ostringstream ss;
         if (m_devAddr.flags & OC_SECURE)