prevent defects resolved (removed not useful code)
[platform/upstream/iotivity.git] / resource / csdk / connectivity / src / ip_adapter / caipserver.c
index c2a4ba6..38f164c 100644 (file)
@@ -347,10 +347,6 @@ static CAResult_t CACreateSocket(int *socketFD, const char *localIp, uint16_t *p
     {
         sockAddr.sin_addr.s_addr = inet_addr(localIp);
     }
-    else
-    {
-        sockAddr.sin_addr.s_addr = htonl(INADDR_ANY);
-    }
 
     int16_t i = 0;
     bool isBound = false;
@@ -627,16 +623,19 @@ CAResult_t CAIPStartUnicastServer(const char *localAddress, uint16_t *port,
         }
         if (netMask)
         {
-            strncpy(info->subNetMask, netMask, strlen(netMask));
+            strncpy(info->subNetMask, netMask, sizeof(info->subNetMask) - 1);
+            info->subNetMask[sizeof(info->subNetMask)-1] = '\0';
             OICFree(netMask);
         }
-        strncpy(info->ipAddress, localAddress, strlen(localAddress));
+        strncpy(info->ipAddress, localAddress, sizeof(info->ipAddress) - 1);
+        info->ipAddress[sizeof(info->ipAddress) - 1] = '\0';
         info->port = *port;
         info->socketFd = unicastServerFd;
         info->isSecured = isSecured;
         info->isServerStarted = true;
         info->isMulticastServer = false;
-        strncpy(info->ifAddr, localAddress, strlen(localAddress));
+        strncpy(info->ifAddr, localAddress, sizeof(info->ifAddr) - 1);
+        info->ifAddr[sizeof(info->ifAddr) - 1] = '\0';
 
         CAResult_t res = CAAddServerInfo(g_serverInfoList, info);
         if (CA_STATUS_OK != res)
@@ -726,17 +725,20 @@ CAResult_t CAIPStartMulticastServer(const char *localAddress, const char *multic
         }
         if (netMask)
         {
-            strncpy(info->subNetMask, netMask, strlen(netMask));
+            strncpy(info->subNetMask, netMask, sizeof(info->subNetMask) - 1);
+            info->subNetMask[sizeof(info->subNetMask) -1] = '\0';
             OICFree(netMask);
         }
 
-        strncpy(info->ipAddress, multicastAddress, strlen(multicastAddress));
+        strncpy(info->ipAddress, multicastAddress, sizeof(info->ipAddress) - 1);
+        info->ipAddress[sizeof(info->ipAddress) -1] = '\0';
         info->port = multicastPort;
         info->socketFd = mulicastServerFd;
         info->isSecured = false;
         info->isServerStarted = true;
         info->isMulticastServer = true;
-        strncpy(info->ifAddr, localAddress, strlen(localAddress));
+        strncpy(info->ifAddr, localAddress, sizeof(info->ifAddr)-1);
+        info->ifAddr[sizeof(info->ifAddr) -1] = '\0';
 
         ret = CAAddServerInfo(g_serverInfoList, info);
 
@@ -804,8 +806,7 @@ CAResult_t CAIPStopServer(const char *interfaceAddress)
                 }
                 CACloseSocket(info->socketFd);
                 OICFree(info);
-                OIC_LOG_V(DEBUG, IP_SERVER_TAG,
-                          "Multicast server is stopped successfully on IF [%s]", info->ifAddr);
+                OIC_LOG(DEBUG, IP_SERVER_TAG, "Multicast server is stopped successfully.");
                 // Reduce list length by 1 as we removed one element.
                 listLength--;
             }
@@ -822,8 +823,7 @@ CAResult_t CAIPStopServer(const char *interfaceAddress)
             {
                 CACloseSocket(info->socketFd);
                 OICFree(info);
-                OIC_LOG_V(DEBUG, IP_SERVER_TAG,
-                          "Unicast server is stopped successfully on IF [%s]", info->ifAddr);
+                OIC_LOG(DEBUG, IP_SERVER_TAG, "Unicast server is stopped successfully.");
                 // Reduce list length by 1 as we removed one element.
                 listLength--;
             }