Kaynağa Gözat

Widens return type to check for unreasonable length values

Signed-off-by: Martin Melik Merkumians <melik-merkumians@acin.tuwien.ac.at>
Martin Melik Merkumians 4 yıl önce
ebeveyn
işleme
76208d50d7
2 değiştirilmiş dosya ile 25 ekleme ve 42 silme
  1. 1 1
      source/src/enet_encap/encap.c
  2. 24 41
      source/src/enet_encap/encap.h

+ 1 - 1
source/src/enet_encap/encap.c

@@ -593,7 +593,7 @@ int GetFreeSessionIndex(void) {
  *                      >0 .. more than one packet received
  *                      <0 .. only fragment of data portion received
  */
-EipInt16 CreateEncapsulationStructure(const EipUint8 *receive_buffer, int receive_buffer_length, EncapsulationData *const encapsulation_data) {
+int_fast32_t CreateEncapsulationStructure(const EipUint8 *receive_buffer, int receive_buffer_length, EncapsulationData *const encapsulation_data) {
   encapsulation_data->communication_buffer_start = (EipUint8*) receive_buffer;
   encapsulation_data->command_code = GetUintFromMessage(&receive_buffer);
   encapsulation_data->data_length = GetUintFromMessage(&receive_buffer);

+ 24 - 41
source/src/enet_encap/encap.h

@@ -39,22 +39,22 @@ typedef enum {
 
 /*** structs ***/
 typedef struct encapsulation_data {
-  CipUint command_code;
-  CipUint data_length;
-  CipUdint session_handle;
-  CipUdint status;
-  CipOctet sender_context[8]; /**< length of 8, according to the specification */
-  CipUdint options;
-  const EipUint8 *communication_buffer_start; /**< Pointer to the communication buffer used for this message */
-  const EipUint8 *current_communication_buffer_position; /**< The current position in the communication buffer during the decoding process */
+    CipUint command_code;
+    CipUint data_length;
+    CipUdint session_handle;
+    CipUdint status;
+    CipOctet sender_context[8]; /**< length of 8, according to the specification */
+    CipUdint options;
+    const EipUint8 *communication_buffer_start; /**< Pointer to the communication buffer used for this message */
+    const EipUint8 *current_communication_buffer_position; /**< The current position in the communication buffer during the decoding process */
 } EncapsulationData;
 
 typedef struct encapsulation_service_information {
-  EipUint16 type_code;
-  EipUint16 length;
-  EipUint16 encapsulation_protocol_version;
-  EipUint16 capability_flags;
-  EipInt8 name_of_service[16];
+    EipUint16 type_code;
+    EipUint16 length;
+    EipUint16 encapsulation_protocol_version;
+    EipUint16 capability_flags;
+    EipInt8 name_of_service[16];
 } EncapsulationServiceInformation;
 
 /*** global variables (public) ***/
@@ -85,48 +85,31 @@ size_t GetSessionFromSocket(const int socket_handle);
 
 void RemoveSession(const int socket);
 
-void CloseSessionBySessionHandle(
-  const CipConnectionObject *const connection_object);
+void CloseSessionBySessionHandle(const CipConnectionObject *const connection_object);
 
-void CloseEncapsulationSessionBySockAddr(
-  const CipConnectionObject *const connection_object);
+void CloseEncapsulationSessionBySockAddr(const CipConnectionObject *const connection_object);
 
 void CloseClass3ConnectionBasedOnSession(size_t encapsulation_session_handle);
 
 /* No reason to use this functions outside the encapsulation layer, they are here for testing */
 typedef struct enip_message ENIPMessage;
 
-void EncapsulateListIdentityResponseMessage(
-  const EncapsulationData *const receive_data,
-  ENIPMessage *const outgoing_message);
+void EncapsulateListIdentityResponseMessage(const EncapsulationData *const receive_data, ENIPMessage *const outgoing_message);
 
-EipInt16 CreateEncapsulationStructure(const EipUint8 *receive_buffer,
-                                      int receive_buffer_length,
-                                      EncapsulationData *const encapsulation_data);
+int_fast32_t CreateEncapsulationStructure(const EipUint8 *receive_buffer, int receive_buffer_length, EncapsulationData *const encapsulation_data);
 
 void SkipEncapsulationHeader(ENIPMessage *const outgoing_message);
 
-void GenerateEncapsulationHeader(const EncapsulationData *const receive_data,
-                                 const size_t command_specific_data_length,
-                                 const size_t session_handle,
-                                 const EncapsulationProtocolErrorCode encapsulation_protocol_status,
-                                 ENIPMessage *const outgoing_message);
+void GenerateEncapsulationHeader(const EncapsulationData *const receive_data, const size_t command_specific_data_length, const size_t session_handle,
+    const EncapsulationProtocolErrorCode encapsulation_protocol_status, ENIPMessage *const outgoing_message);
 
-void HandleReceivedListServicesCommand(
-  const EncapsulationData *const receive_data,
-  ENIPMessage *const outgoing_message);
+void HandleReceivedListServicesCommand(const EncapsulationData *const receive_data, ENIPMessage *const outgoing_message);
 
-void HandleReceivedListInterfacesCommand(
-  const EncapsulationData *const receive_data,
-  ENIPMessage *const outgoing_message);
+void HandleReceivedListInterfacesCommand(const EncapsulationData *const receive_data, ENIPMessage *const outgoing_message);
 
-void HandleReceivedRegisterSessionCommand(int socket,
-                                          const EncapsulationData *const receive_data,
-                                          ENIPMessage *const outgoing_message);
+void HandleReceivedRegisterSessionCommand(int socket, const EncapsulationData *const receive_data, ENIPMessage *const outgoing_message);
 
-EipStatus HandleReceivedSendRequestResponseDataCommand(
-  const EncapsulationData *const receive_data,
-  const struct sockaddr *const originator_address,
-  ENIPMessage *const outgoing_message);
+EipStatus HandleReceivedSendRequestResponseDataCommand(const EncapsulationData *const receive_data, const struct sockaddr *const originator_address,
+    ENIPMessage *const outgoing_message);
 
 #endif /* OPENER_ENCAP_H_ */