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 7a87de1..e75c49f 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 688892b..5d18828 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 b86a50d..88396ee 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 2343a5a..bf496ed 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 5f46dd3..28f5750 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 ce2b57d..87110a4 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 6453309..41024e4 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 3e12b5e..d9d76f7 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);