소스 검색

Fixes some scan coverity issues

Signed-off-by: CapXilinx <melik-merkumians@acin.tuwien.ac.at>
CapXilinx 8 년 전
부모
커밋
0cc0f1aaea
4개의 변경된 파일15개의 추가작업 그리고 6개의 파일을 삭제
  1. 1 0
      source/src/cip/appcontype.c
  2. 3 3
      source/src/cip/cipcommon.c
  3. 3 2
      source/src/cip/cipconnectionobject.c
  4. 8 1
      source/src/ports/generic_networkhandler.c

+ 1 - 0
source/src/cip/appcontype.c

@@ -428,6 +428,7 @@ bool ConnectionWithSameConfigPointExists(const EipUint32 config_point) {
 
   while (NULL != node) {
     CipConnectionObject *connection = node->data;
+    OPENER_ASSERT(NULL != connection);
     if (config_point == connection->configuration_path.instance_id) {
       return (NULL != connection);
     }

+ 3 - 3
source/src/cip/cipcommon.c

@@ -138,8 +138,8 @@ CipInstance *AddCipInstances(CipClass *RESTRICT const cip_class,
     instance_number++; /*    keep track of what the first new instance number will be */
   }
 
-  CipInstance *current_instance = current_instance = (CipInstance *) CipCalloc(
-                                    number_of_instances, sizeof(CipInstance) ); /* allocate a block of memory for all created instances*/
+  CipInstance *current_instance = (CipInstance *) CipCalloc(
+    number_of_instances, sizeof(CipInstance) );                                 /* allocate a block of memory for all created instances*/
   CipInstance *first_instance = current_instance; /* allocate a block of memory for all created instances*/
 
   OPENER_ASSERT(NULL != current_instance);
@@ -172,7 +172,7 @@ CipInstance *AddCIPInstance(CipClass *RESTRICT const class,
                             const EipUint32 instance_id) {
   CipInstance *instance = GetCipInstance(class, instance_id);
 
-  if (0 == instance) { /*we have no instance with given id*/
+  if (NULL == instance) { /*we have no instance with given id*/
     instance = AddCipInstances(class, 1);
     instance->instance_number = instance_id;
   }

+ 3 - 2
source/src/cip/cipconnectionobject.c

@@ -558,8 +558,9 @@ void ConnectionObjectResetLastPackageInactivityTimerValue(
 
 uint64_t ConnectionObjectCalculateRegularInactivityWatchdogTimerValue(
   const CipConnectionObject *const connection_object) {
-  return ( ( (connection_object->o_to_t_requested_packet_interval) /
-             1000 ) << (2 + connection_object->connection_timeout_multiplier) );
+  return ( ( (uint64_t)(connection_object->o_to_t_requested_packet_interval) /
+             (uint64_t)1000 ) <<
+           (2 + connection_object->connection_timeout_multiplier) );
 }
 
 

+ 8 - 1
source/src/ports/generic_networkhandler.c

@@ -680,7 +680,14 @@ EipStatus HandleDataOnTcpSocket(int socket) {
     struct sockaddr sender_address;
     memset( &sender_address, 0, sizeof(sender_address) );
     socklen_t fromlen = sizeof(sender_address);
-    getpeername(socket, (struct sockaddr *)&sender_address, &fromlen);
+    if (getpeername(socket, (struct sockaddr *)&sender_address, &fromlen) < 0) {
+      int error_code = GetSocketErrorNumber();
+      char *error_message = GetErrorMessage(error_code);
+      OPENER_TRACE_ERR("networkhandler: could not get peername: %d - %s\n",
+                       error_code,
+                       error_message);
+      FreeErrorMessage(error_message);
+    }
 
     number_of_read_bytes = HandleReceivedExplictTcpData(
       socket, g_ethernet_communication_buffer, data_size, &remaining_bytes,