]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #2241 in SNORT/snort3 from ~KATHARVE/snort3:coverity_fixes to...
authorMike Stepanek (mstepane) <mstepane@cisco.com>
Fri, 5 Jun 2020 18:43:30 +0000 (18:43 +0000)
committerMike Stepanek (mstepane) <mstepane@cisco.com>
Fri, 5 Jun 2020 18:43:30 +0000 (18:43 +0000)
Squashed commit of the following:

commit 689610e78e3964183dd9743cc2b284cc78520e28
Author: Katura Harvey <katharve@cisco.com>
Date:   Thu Jun 4 17:08:10 2020 -0400

    service_inspectors: remove some redundant initializations and lookups, move some field initializations into the constructor

src/service_inspectors/http2_inspect/http2_data_cutter.h
src/service_inspectors/http2_inspect/http2_hpack.cc
src/service_inspectors/http2_inspect/http2_hpack.h
src/service_inspectors/http_inspect/http_msg_head_shared.cc
src/service_inspectors/http_inspect/http_msg_head_shared.h
src/service_inspectors/modbus/modbus.cc
src/service_inspectors/modbus/modbus_decode.cc
src/service_inspectors/modbus/modbus_decode.h
src/service_inspectors/s7commplus/s7comm.cc
src/service_inspectors/s7commplus/s7comm_decode.cc
src/service_inspectors/s7commplus/s7comm_decode.h

index 12557aca5b7f3f207277eecbbf92326ba1c3ac03..22c7438653ade6c870e62bc26fc1b4d1b2082e31 100644 (file)
@@ -45,13 +45,13 @@ private:
     // total per frame - scan
     uint32_t frame_length;
     uint32_t data_len;
-    uint32_t padding_len = 0;
+    uint32_t padding_len;
     uint8_t frame_flags;
     // accumulating - scan
     uint32_t frame_bytes_seen = 0;
     uint32_t bytes_sent_http = 0;
-    uint32_t data_bytes_read = 0;
-    uint32_t padding_read = 0;
+    uint32_t data_bytes_read;
+    uint32_t padding_read;
     // leftover from previous scan call
     uint32_t leftover_bytes = 0;
     uint32_t leftover_padding = 0;
index 9691261e53ab8e11e9b34aeeaaa777e7e68a9021..5afa143c00cdb1ae282834df5bea4395ee5ad657 100644 (file)
@@ -365,6 +365,7 @@ bool Http2HpackDecoder::decode_headers(const uint8_t* encoded_headers,
     events = stream_events;
     infractions = stream_infractions;
     pseudo_headers_fragment_size = 0;
+    decode_error = false;
 
     // A maximum of two table size updates are allowed, and must be at the start of the header block
     table_size_update_allowed = true;
index f2d2e9407bc586a92765207047c303a06d232a83..54a56a6f43d999d2ec05eef558be4d61ab6bdd39 100644 (file)
@@ -72,10 +72,10 @@ public:
     HpackIndexTable* get_decode_table() { return &decode_table; }
 
 private:
-    Http2StartLine* start_line = nullptr;
+    Http2StartLine* start_line;
     uint32_t decoded_headers_size;
-    uint32_t pseudo_headers_fragment_size = 0;
-    bool decode_error = false;
+    uint32_t pseudo_headers_fragment_size;
+    bool decode_error;
     Http2EventGen* events;
     Http2Infractions* infractions;
 
index 4a9f1abfac091edd67d2a3718ae7199cc4ea0ec1..4328a39c3e6b6bdac5860d22220c79e8a107fefe 100644 (file)
@@ -72,9 +72,7 @@ void HttpMsgHeadShared::create_norm_head_list()
             {
                 headers_present[header_name_id[j]] = true;
                 NormalizedHeader* tmp_ptr = norm_heads;
-                norm_heads = new NormalizedHeader(header_name_id[j]);
-                norm_heads->next = tmp_ptr;
-                norm_heads->count = 1;
+                norm_heads = new NormalizedHeader(tmp_ptr, 1, header_name_id[j]);
             }
         }
     }
index 4dbbccaf4bd2290ded2f72369ba8eda57c447355..6016b842c3f96d480eb57684f55057162c08f196 100644 (file)
@@ -107,7 +107,8 @@ private:
 
     struct NormalizedHeader
     {
-        NormalizedHeader(HttpEnums::HeaderId id_) : id(id_) {}
+        NormalizedHeader(NormalizedHeader* next_, int32_t count_, HttpEnums::HeaderId id_) :
+            next(next_), count(count_), id(id_) {}
 
         Field norm;
         NormalizedHeader* next;
index 36a4b6280583189ae56693e7bd9217d1639834b6..a3918fc3d5f88431f1af99c267c02186d1929f90 100644 (file)
@@ -114,7 +114,7 @@ void Modbus::eval(Packet* p)
     // evaluating on the first PDU. Setting this flag stops the caching.
     p->packet_flags |= PKT_ALLOW_MULTIPLE_DETECT;
 
-    if ( !ModbusDecode(p) )
+    if ( !ModbusDecode(p, mfd) )
         mfd->reset();
 }
 
index 82809bbfca217b73814b702c59c9636b3424ff87..0f7bf2485647eb1d51f47597307a72cea2f2e6f0 100644 (file)
@@ -405,16 +405,13 @@ static void ModbusCheckReservedFuncs(const modbus_header_t* header, Packet* p)
     }
 }
 
-bool ModbusDecode(Packet* p)
+bool ModbusDecode(Packet* p, ModbusFlowData* mfd)
 {
     const modbus_header_t* header;
 
     if (p->dsize < MODBUS_MIN_LEN)
         return false;
 
-    ModbusFlowData* mfd =
-        (ModbusFlowData*)p->flow->get_flow_data(ModbusFlowData::inspector_id);
-
     /* Lay the header struct over the payload */
     header = (const modbus_header_t*)p->data;
 
index a5a5cd91dbab70cde3a2680716ccd1d072d305a5..d00fec84b5926cf734920be373fa4c191e0d2d0b 100644 (file)
@@ -27,10 +27,12 @@ namespace snort
 struct Packet;
 }
 
+class ModbusFlowData;
+
 /* Need 8 bytes for MBAP Header + Function Code */
 #define MODBUS_MIN_LEN 8
 
-bool ModbusDecode(snort::Packet*);
+bool ModbusDecode(snort::Packet*, ModbusFlowData* mfd);
 
 #endif
 
index 82de7ed52d98ef2ddb7a8ba72af44ce8ab654a8f..ad9c9da38b4bf314a9396d2270cdcaad6b0aa76b 100644 (file)
@@ -114,7 +114,7 @@ void S7commplus::eval(Packet* p)
     // evaluating on the first PDU. Setting this flag stops the caching.
     p->packet_flags |= PKT_ALLOW_MULTIPLE_DETECT;
 
-    if ( !S7commplusDecode(p)
+    if ( !S7commplusDecode(p, mfd))
         mfd->reset();
 }
 
index f3adf4e729f32dae88a16ef75fdec90cbf8351e1..284d99915a3ff507a71df5956303f9efd60df3f1 100644 (file)
@@ -101,7 +101,7 @@ static bool S7commPlusProtocolDecode(S7commplusSessionData* session, Packet* p)
     return true;
 }
 
-bool S7commplusDecode(Packet* p)
+bool S7commplusDecode(Packet* p, S7commplusFlowData* mfd)
 {
     const TpktHeader* tpkt_header;
     const CotpHeader* cotp_header;
@@ -111,8 +111,6 @@ bool S7commplusDecode(Packet* p)
     if (p->dsize < TPKT_MIN_HDR_LEN)
         return false;
 
-    S7commplusFlowData* mfd =
-        (S7commplusFlowData*)p->flow->get_flow_data(S7commplusFlowData::inspector_id);
     tpkt_header = (const TpktHeader*)p->data;
     cotp_header = (const CotpHeader*)(p->data + sizeof(TpktHeader));
     tpkt_length = ntohs(tpkt_header->length);
index 6513c3848dc0089ce5b53db35647113208b80893..7fbdf7fc85599c0172b7ec930ada91bdacc69679 100644 (file)
@@ -27,6 +27,8 @@ namespace snort
 struct Packet;
 }
 
+class S7commplusFlowData;
+
 /* S7comm defines */
 #define S7COMMPLUS_PDUTYPE_CONNECT                 0x01
 #define S7COMMPLUS_PDUTYPE_DATA                    0x02
@@ -59,7 +61,7 @@ struct Packet;
 #define S7COMMPLUS_RESERVED_FUNCTION_STR \
     "(spp_s7commplus): Reserved S7commplus function code in use."
 
-bool S7commplusDecode(snort::Packet*);
+bool S7commplusDecode(snort::Packet*, S7commplusFlowData* mfd);
 
 #endif