Klockwork fixes for Routing Manager and CA
authorvimala.v <vimala.v@samsung.com>
Tue, 29 Sep 2015 11:49:37 +0000 (17:19 +0530)
committerPatrick Lankswert <patrick.lankswert@intel.com>
Tue, 29 Sep 2015 23:24:32 +0000 (23:24 +0000)
If accepted, this changeset should be cherrypicked to 1.0.0-dev.

Change-Id: I2bfaa017c3fafc5a5cd8d4c248564aa4eff88f76
Signed-off-by: vimala.v <vimala.v@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/3277
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Patrick Lankswert <patrick.lankswert@intel.com>
resource/csdk/connectivity/common/src/ulinklist.c
resource/csdk/connectivity/samples/arduino/casample.cpp
resource/csdk/connectivity/samples/tizen/casample.c
resource/csdk/connectivity/src/camessagehandler.c
resource/csdk/connectivity/src/ip_adapter/arduino/caipserver_eth.cpp
resource/csdk/connectivity/src/ip_adapter/arduino/caipserver_wifi.cpp
resource/csdk/routing/src/routingmanager.c
resource/csdk/routing/src/routingtablemanager.c

index 7a87de18a59b330931d2e6f74cd1d6fbe11b9318..e75c49f66c24c4a0d3f11450f20c195068c4bd85 100644 (file)
@@ -181,8 +181,11 @@ CAResult_t u_linklist_remove(u_linklist_t *linklist, u_linklist_iterator_t **ite
 
 uint32_t u_linklist_length(const u_linklist_t *linklist)
 {
-    VERIFY_NON_NULL(linklist, TAG, "list is null");
-
+    if (NULL == linklist)
+    {
+        OIC_LOG(ERROR, TAG, "linklist is NULL");
+        return 0;
+    }
     return linklist->size;
 }
 
index 688892bb2a4a1060e0c7fead0fca8972a21866b2..5d18828e6aed357e1110fdc75ff8890fa3d2a3b3 100644 (file)
@@ -341,6 +341,7 @@ void SendRequest()
     if (res != CA_STATUS_OK || (!token))
     {
         Serial.println("token error");
+        CADestroyEndpoint(endpoint);
         return;
     }
 
@@ -425,6 +426,7 @@ void SendRequestAll()
     if (res != CA_STATUS_OK || (!token))
     {
         Serial.println("token error");
+        CADestroyEndpoint(endpoint);
         return;
     }
 
@@ -508,6 +510,7 @@ void SendNotification()
     if (res != CA_STATUS_OK || (!token))
     {
         Serial.println("token error");
+        CADestroyEndpoint(endpoint);
         return;
     }
 
index b86a50d37e5bc9e838e53322b9757a165c7af336..88396eeafaa423bff084b108f06e125bc546f9d4 100644 (file)
@@ -680,7 +680,6 @@ void send_request_all()
     if (CA_STATUS_OK != res)
     {
         printf("Could not send request to all\n");
-        CADestroyEndpoint(endpoint);
     }
     else
     {
index 2343a5a2f0e1398c95e57bd677e5ec5d3835837d..bf496ed6708b3c1035a2d5c9f23030a9ab9a8291 100644 (file)
@@ -1381,6 +1381,7 @@ static void CASendErrorInfo(const CAEndpoint_t *endpoint, const CAInfo_t *info,
     if (CA_STATUS_OK != res)
     {
         OICFree(cadata);
+        OICFree(errorInfo);
         CAFreeEndpoint(ep);
         return;
     }
index 5f46dd31a1ba3153715b7b682638477d9292c4c2..28f57502e07f214e221f8d8297dbeb5e0ca54264 100644 (file)
@@ -332,7 +332,10 @@ CAResult_t CAGetIPInterfaceInformation(CAEndpoint_t **info, uint32_t *size)
     for (uint32_t i = 0, j = 0; i < len; i++)
     {
         CAInterface_t *ifitem = (CAInterface_t *)u_arraylist_get(iflist, i);
-
+        if(!ifitem)
+        {
+            continue;
+        }
         unsigned char *addr=  (unsigned char *) &(ifitem->ipv4addr);
         snprintf(eps[j].addr, MAX_ADDR_STR_SIZE_CA, "%d.%d.%d.%d", addr[0], addr[1], addr[2], addr[3]);
 
index ce2b57d7555e2cb3f7c1b9ebd921ff6588c42f36..87110a4ca0857035850376bdc329dffaf229b3ce 100644 (file)
@@ -275,7 +275,10 @@ CAResult_t CAGetIPInterfaceInformation(CAEndpoint_t **info, uint32_t *size)
     for (uint32_t i = 0, j = 0; i < len; i++)
     {
         CAInterface_t *ifitem = (CAInterface_t *)u_arraylist_get(iflist, i);
-
+        if(!ifitem)
+        {
+            continue;
+        }
         unsigned char *addr=  (unsigned char *) &(ifitem->ipv4addr);
         snprintf(eps[j].addr, MAX_ADDR_STR_SIZE_CA, "%d.%d.%d.%d", addr[0], addr[1], addr[2], addr[3]);
 
index 645330962e6c952f2cef80af9d44867c25413706..41024e4760f77f625c19279f482f493215e71b65 100644 (file)
@@ -351,6 +351,7 @@ OCStackResult RMHandleResponsePayload(const OCDevAddr *devAddr, const OCRepPaylo
     if (gatewayId == g_GatewayID)
     {
         OC_LOG(INFO, TAG, "-------------->Own entry, continue!!");
+        RTMFreeGatewayRouteTable(&gatewayTableList);
         return OC_STACK_ERROR;
     }
     // Convert OCDevAddr to endpoint address
@@ -369,11 +370,13 @@ OCStackResult RMHandleResponsePayload(const OCDevAddr *devAddr, const OCRepPaylo
             OC_LOG(ERROR, TAG, "Few packet drops are found, sequence number is not matching");
             // Send a observe request to the gateway.
             RMSendObserveRequest(devAddr, NULL);
+            RTMFreeGatewayRouteTable(&gatewayTableList);
             return result;
         }
         else if (OC_STACK_DUPLICATE_REQUEST == result)
         {
             OC_LOG(ERROR, TAG, "Same sequence number is received");
+            RTMFreeGatewayRouteTable(&gatewayTableList);
             return result;
         }
     }
@@ -393,7 +396,19 @@ OCStackResult RMHandleResponsePayload(const OCDevAddr *devAddr, const OCRepPaylo
 
     // Create a list to add the updated entries and notify the observers
     u_linklist_t *updatedTableList = u_linklist_create();
+    if(!updatedTableList)
+    {
+        OC_LOG(DEBUG, TAG, "Failed to allocate memory");
+        return OC_STACK_NO_MEMORY;
+    }
+
     u_linklist_t *alternativeRouteList = u_linklist_create();
+    if(!alternativeRouteList)
+    {
+        OC_LOG(DEBUG, TAG, "Failed to allocate memory");
+        return OC_STACK_NO_MEMORY;
+    }
+
     OCRepPayload *updatedPayload = NULL;
     if (false == doRemoveEntry)
     {
@@ -540,6 +555,7 @@ OCStackResult RMHandleGETRequest(const OCServerRequest *request, const OCResourc
     if (OC_STACK_OK != result)
     {
         OC_LOG_V(DEBUG, TAG, "Send response failed[%d]", result);
+        RMPFreePayload(payload);
         return result;
     }
 
@@ -832,6 +848,11 @@ void RMSendDeleteToNeighbourNodes()
             for (uint32_t i = 0; i < u_arraylist_length(entry->destination->destIntfAddr); i++)
             {
                 RTMDestIntfInfo_t *dest = u_arraylist_get(entry->destination->destIntfAddr, i);
+                if (!dest)
+                {
+                    OC_LOG(ERROR, RM_TAG, "Failed to get dest address");
+                    continue;
+                }
                 OCDevAddr devAddr = {.adapter = OC_DEFAULT_ADAPTER};
                 CopyEndpointToDevAddr(&(dest->destIntfAddr), &devAddr);
                 OC_LOG_V(DEBUG, TAG, "\nDestination interface addresses: %s[%d], OCDevAddr: %s[%d]",
@@ -839,7 +860,7 @@ void RMSendDeleteToNeighbourNodes()
                 RMSendDeleteRequest(&devAddr, payload);
             }
         }
-        RMPFreePayload(payload);
+
         u_linklist_get_next(&iterTable);
     }
 
index 3e12b5ebc69886d1891a848b856c4e3251b978b3..d9d76f786d62cbd48eb21813f3f6305767c8a6b0 100644 (file)
@@ -240,6 +240,11 @@ OCStackResult RTMAddGatewayEntry(uint32_t gatewayId, uint32_t nextHop, uint32_t
     if (NULL == *gatewayTable)
     {
         *gatewayTable = u_linklist_create();
+        if (NULL == *gatewayTable)
+        {
+            OC_LOG(ERROR, TAG, "u_linklist_create failed");
+            return OC_STACK_NO_MEMORY;
+        }
     }
 
     if (1 == routeCost && 0 != nextHop)
@@ -504,6 +509,11 @@ OCStackResult RTMAddEndpointEntry(uint16_t *endpointId, const CAEndpoint_t *dest
     if (NULL == *endpointTable)
     {
         *endpointTable = u_linklist_create();
+        if (NULL == *endpointTable)
+        {
+            OC_LOG(ERROR, TAG, "u_linklist_create failed");
+            return OC_STACK_NO_MEMORY;
+        }
     }
 
     u_linklist_iterator_t *iterTable = NULL;
@@ -636,6 +646,11 @@ OCStackResult RTMRemoveGatewayEntry(uint32_t gatewayId, u_linklist_t **removedGa
     if (NULL == *removedGatewayNodes)
     {
         *removedGatewayNodes = u_linklist_create();
+        if (NULL == *removedGatewayNodes)
+        {
+            OC_LOG(ERROR, TAG, "u_linklist_create failed");
+            return OC_STACK_NO_MEMORY;
+        }
     }
     OCStackResult ret = OC_STACK_OK;
     u_linklist_init_iterator(*gatewayTable, &iterTable);
@@ -700,6 +715,10 @@ OCStackResult RTMRemoveGatewayDestEntry(uint32_t gatewayId, uint32_t nextHop,
             for (uint32_t i = 0; i < u_arraylist_length(entry->destination->destIntfAddr); i++)
             {
                 RTMDestIntfInfo_t *destCheck = u_arraylist_get(entry->destination->destIntfAddr, i);
+                if(!destCheck)
+                {
+                    continue;
+                }
                 if (0 == memcmp(destCheck->destIntfAddr.addr, destInfAdr->destIntfAddr.addr,
                     strlen(destInfAdr->destIntfAddr.addr))
                     && destInfAdr->destIntfAddr.port == destCheck->destIntfAddr.port)
@@ -829,6 +848,11 @@ void RTMGetNeighbours(u_linklist_t **neighbourNodes, const u_linklist_t *gateway
     RM_NULL_CHECK_VOID(gatewayTable, TAG, "gatewayTable");
 
     *neighbourNodes = u_linklist_create();
+    if (NULL == *neighbourNodes)
+    {
+        OC_LOG(ERROR, TAG, "u_linklist_create failed");
+        return;
+    }
     u_linklist_iterator_t *iterTable = NULL;
     u_linklist_init_iterator(gatewayTable, &iterTable);
     while (NULL != iterTable)
@@ -1022,6 +1046,10 @@ OCStackResult RTMUpdateDestinationIntfAdr(uint32_t gatewayId, RTMDestIntfInfo_t
             {
                 RTMDestIntfInfo_t *removeAdr =
                     u_arraylist_get(entry->destination->destIntfAddr, i);
+                if (!removeAdr)
+                {
+                    continue;
+                }
                 if (0 == memcmp(removeAdr->destIntfAddr.addr, destInterfaces.destIntfAddr.addr,
                     strlen(destInterfaces.destIntfAddr.addr))
                     && destInterfaces.destIntfAddr.port == removeAdr->destIntfAddr.port)
@@ -1108,6 +1136,12 @@ OCStackResult RTMUpdateDestAddrValidity(u_linklist_t **invalidTable, u_linklist_
     RM_NULL_CHECK_WITH_RET(*gatewayTable, TAG, "*gatewayTable");
 
     *invalidTable = u_linklist_create();
+    if (NULL == *invalidTable)
+    {
+        OC_LOG(ERROR, TAG, "u_linklist_create failed");
+        return OC_STACK_NO_MEMORY;
+    }
+
     u_linklist_iterator_t *iterTable = NULL;
     uint64_t presentTime = RTMGetCurrentTime();
 
@@ -1125,6 +1159,10 @@ OCStackResult RTMUpdateDestAddrValidity(u_linklist_t **invalidTable, u_linklist_
             for (uint32_t i = 0; i < u_arraylist_length(entry->destination->destIntfAddr); i++)
             {
                 RTMDestIntfInfo_t *destCheck = u_arraylist_get(entry->destination->destIntfAddr, i);
+                if (!destCheck)
+                {
+                    continue;
+                }
                 if (GATEWAY_ALIVE_TIMEOUT < (presentTime - destCheck->timeElapsed))
                 {
                     destCheck->isValid = false;
@@ -1150,6 +1188,11 @@ OCStackResult RTMRemoveInvalidGateways(u_linklist_t **invalidTable, u_linklist_t
     RM_NULL_CHECK_WITH_RET(*gatewayTable, TAG, "*gatewayTable");
 
     *invalidTable = u_linklist_create();
+    if (NULL == *invalidTable)
+    {
+        OC_LOG(ERROR, TAG, "u_linklist_create failed");
+        return OC_STACK_NO_MEMORY;
+    }
 
     u_linklist_iterator_t *iterTable = NULL;
     u_linklist_init_iterator(*gatewayTable, &iterTable);
@@ -1167,7 +1210,7 @@ OCStackResult RTMRemoveInvalidGateways(u_linklist_t **invalidTable, u_linklist_t
             for (uint32_t i = 0; i < u_arraylist_length(entry->destination->destIntfAddr); i++)
             {
                 RTMDestIntfInfo_t *destCheck = u_arraylist_get(entry->destination->destIntfAddr, i);
-                if (!destCheck->isValid)
+                if (!destCheck && !destCheck->isValid)
                 {
                     void *data = u_arraylist_remove(entry->destination->destIntfAddr, i);
                     OICFree(data);