Fix static analysis issues in CA, rd_client and ocstack
authorMinji Park <minjii.park@samsung.com>
Wed, 9 Nov 2016 09:33:14 +0000 (18:33 +0900)
committerHabib Virji <habib.virji@samsung.com>
Fri, 11 Nov 2016 12:09:31 +0000 (12:09 +0000)
- variable initialization and null checking added

Change-Id: Ibb47193ccb480941abfa71b0d32020891d2025f6
Signed-off-by: Minji Park <minjii.park@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/14157
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Jaehong Jo <jaehong.jo@samsung.com>
Reviewed-by: Habib Virji <habib.virji@samsung.com>
resource/csdk/connectivity/src/bt_le_adapter/caleadapter.c
resource/csdk/connectivity/src/ip_adapter/android/ifaddrs.c
resource/csdk/resource-directory/src/rd_client.c
resource/csdk/stack/src/ocstack.c

index ad0fa00..a7a66ec 100644 (file)
@@ -3539,6 +3539,13 @@ static void CALERemoveReceiveQueueData(u_arraylist_t *dataInfoList, const char*
         for (uint32_t i = 0; i < arrayLength; i++)
         {
             uint16_t *port = (uint16_t *)u_arraylist_get(portList, i);
+            if (!port)
+            {
+                OIC_LOG(ERROR, CALEADAPTER_TAG, "Failed to get port from sender info !");
+                u_arraylist_destroy(portList);
+                return;
+            }
+
             OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "port : %X", *port);
 
             if (CA_STATUS_OK == CALEGetSenderInfo(address, *port,
@@ -3584,6 +3591,11 @@ static CAResult_t CALEGetPortsFromSenderInfo(const char *leAddress,
         if (!strncmp(info->remoteEndpoint->addr, leAddress, addrLength))
         {
             uint16_t *port = (uint16_t *)OICMalloc(sizeof(uint16_t));
+            if (!port)
+            {
+                OIC_LOG(ERROR, CALEADAPTER_TAG, "memory allocation failed!");
+                return CA_MEMORY_ALLOC_FAILED;
+            }
             *port = info->remoteEndpoint->port;
             u_arraylist_add(portList, (void *)port);
         }
index 44e9fb6..a2b07c0 100644 (file)
@@ -46,13 +46,14 @@ typedef struct {
 
 static bool CASendNetlinkMessage(int netlinkFd, const void* data, size_t len)
 {
-    ssize_t sentByteCount = TEMP_FAILURE_RETRY(send(netlinkFd, data, len, 0));
+    ssize_t sentByteCount = 0;
+    sentByteCount = TEMP_FAILURE_RETRY(send(netlinkFd, data, len, 0));
     return (sentByteCount == (ssize_t)(len));
 }
 
 void CAFreeIfAddrs(struct ifaddrs *ifa)
 {
-    struct ifaddrs *cur;
+    struct ifaddrs *cur = NULL;
     while (ifa)
     {
         cur = ifa;
@@ -89,6 +90,11 @@ static struct ifaddrs *CAParsingAddr(struct nlmsghdr *recvMsg)
         {
             case IFA_ADDRESS:
                 ss = (struct sockaddr_storage*)OICCalloc(1, sizeof(struct sockaddr_storage));
+                if (!ss)
+                {
+                    OIC_LOG(ERROR, TAG, "Memory allocation failed!");
+                    return NULL;
+                }
                 ss->ss_family = ifaddrmsgData-> ifa_family;
 
                 if (ifaddrmsgData-> ifa_family == AF_INET)
@@ -200,4 +206,4 @@ exit:
         return CA_SOCKET_OPERATION_FAILED;
     }
     return CA_STATUS_OK;
-}
\ No newline at end of file
+}
index 839c725..5bf0cb2 100644 (file)
@@ -185,6 +185,19 @@ OCStackResult OCRDPublishWithDeviceId(const char *host, const unsigned char *id,
 
             size_t mtDim[MAX_REP_ARRAY_DEPTH] = {1, 0, 0};
             char **mediaType = (char **)OICMalloc(sizeof(char *) * 1);
+            if (!mediaType)
+            {
+                OIC_LOG(ERROR, TAG, "Memory allocation failed!");
+
+                for(uint8_t i = 0; i < nPubResHandles; i++)
+                {
+                    OCRepPayloadDestroy(linkArr[i]);
+                }
+                OICFree(linkArr);
+                OCRepPayloadDestroy(rdPayload);
+                return OC_STACK_NO_MEMORY;
+            }
+
             mediaType[0] = OICStrdup(DEFAULT_MESSAGE_TYPE);
             OCRepPayloadSetStringArrayAsOwner(link, OC_RSRVD_MEDIA_TYPE, mediaType,
             mtDim);
index c2b5e15..4c10b76 100644 (file)
@@ -4886,7 +4886,7 @@ OCStackResult OCUpdateResourceInsWithResponse(const char *requestUri,
                 {
                     OCRepPayload *rdPayload = (OCRepPayload *) response->payload;
                     OCRepPayload **links = NULL;
-                    size_t dimensions[MAX_REP_ARRAY_DEPTH];
+                    size_t dimensions[MAX_REP_ARRAY_DEPTH] = { 0 };
                     if (OCRepPayloadGetPropObjectArray(rdPayload, OC_RSRVD_LINKS,
                                                        &links, dimensions))
                     {