]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #2225 in SNORT/snort3 from ~SBAIGAL/snort3:coverity_fix2 to master
authorSteve Chew (stechew) <stechew@cisco.com>
Mon, 1 Jun 2020 18:33:07 +0000 (18:33 +0000)
committerSteve Chew (stechew) <stechew@cisco.com>
Mon, 1 Jun 2020 18:33:07 +0000 (18:33 +0000)
Squashed commit of the following:

commit 0d0ea620abf03e13f68e3ce714eefa26b2cb310b
Author: Steven Baigal (sbaigal) <sbaigal@cisco.com>
Date:   Thu May 14 10:09:44 2020 -0400

    coverity: fix issued found by Coverity scans

17 files changed:
src/codecs/ip/cd_udp.cc
src/connectors/tcp_connector/tcp_connector.h
src/connectors/tcp_connector/tcp_connector_config.h
src/detection/fp_create.cc
src/detection/ips_context.h
src/file_api/file_capture.cc
src/file_api/file_flows.cc
src/file_api/file_log.cc
src/file_api/file_mempool.h
src/framework/codec.h
src/framework/inspector.h
src/mime/file_mime_log.h
src/packet_io/active.cc
src/parser/parse_rule.cc
src/parser/parse_stream.cc
src/ports/port_table.cc
src/sfip/sf_ipvar.cc

index e6745b41e04e4a44633b35c3d4cb6278dcf4a6d8..50125b644308bccfe73ad0bd51a9793b0a1ea5d4 100644 (file)
@@ -117,13 +117,13 @@ public:
     bool is_vxlan_port(uint16_t port)
     { return vxlan_ports.test(port); }
 
-    void set_gtp_ports(PortBitSet ports)
+    void set_gtp_ports(const PortBitSet& ports)
     {
         gtp_ports = ports;
         gtp_decode = ports.any();
     }
 
-    void set_vxlan_ports(PortBitSet ports)
+    void set_vxlan_ports(const PortBitSet& ports)
     {
         vxlan_ports = ports;
         vxlan_decode = ports.any();
index 2c0564432c04a35d468e2b03910026070dcd1bab..9caf29883314cccb4392200ce953c1a08a628f5a 100644 (file)
@@ -81,7 +81,7 @@ public:
     int sock_fd;
 
 private:
-    bool run_thread;
+    bool run_thread = false;
     std::thread* receive_thread;
     void start_receive_thread();
     void stop_receive_thread();
index f3c663c55eb7b6033285f2954ea1d575dd5a59c2..5c0cd56e94a57144ce1a7f4bdcba722b2f009f85 100644 (file)
@@ -32,9 +32,9 @@ public:
     TcpConnectorConfig()
     { direction = snort::Connector::CONN_DUPLEX; async_receive = true; }
 
-    uint16_t base_port;
+    uint16_t base_port = 0;
     std::string address;
-    Setup setup;
+    Setup setup = {};
     bool async_receive;
 
     typedef std::vector<TcpConnectorConfig*> TcpConnectorConfigSet;
index c9e6bc96e1e55133e6f178d71e2467cec1e24057..cca0034a1f5b0772bfc4128cb736490f14bbeac1 100644 (file)
@@ -174,7 +174,7 @@ static int otn_create_tree(OptTreeNode* otn, void** existing_tree, Mpse::MpseTyp
 
             child->num_children++;
             child->children = (detection_option_tree_node_t**)
-                snort_calloc(child->num_children, sizeof(child->children));
+                snort_calloc(child->num_children, sizeof(detection_option_tree_node_t*));
             child->is_relative = opt_fp->isRelative;
 
             if (node && child->is_relative)
@@ -245,7 +245,7 @@ static int otn_create_tree(OptTreeNode* otn, void** existing_tree, Mpse::MpseTyp
                 {
                     node->num_children++;
                     tmp_children = (detection_option_tree_node_t**)
-                        snort_calloc(node->num_children, sizeof(tmp_children));
+                        snort_calloc(node->num_children, sizeof(detection_option_tree_node_t*));
                     memcpy(tmp_children, node->children,
                         sizeof(detection_option_tree_node_t*) * (node->num_children-1));
 
@@ -289,7 +289,7 @@ static int otn_create_tree(OptTreeNode* otn, void** existing_tree, Mpse::MpseTyp
             detection_option_tree_node_t** tmp_children;
             root->num_children++;
             tmp_children = (detection_option_tree_node_t**)
-                snort_calloc(root->num_children, sizeof(tmp_children));
+                snort_calloc(root->num_children, sizeof(detection_option_tree_node_t*));
             memcpy(tmp_children, root->children,
                 sizeof(detection_option_tree_node_t*) * (root->num_children-1));
             snort_free(root->children);
@@ -304,7 +304,7 @@ static int otn_create_tree(OptTreeNode* otn, void** existing_tree, Mpse::MpseTyp
             detection_option_tree_node_t** tmp_children;
             node->num_children++;
             tmp_children = (detection_option_tree_node_t**)
-                snort_calloc(node->num_children, sizeof(tmp_children));
+                snort_calloc(node->num_children, sizeof(detection_option_tree_node_t*));
             memcpy(tmp_children, node->children,
                 sizeof(detection_option_tree_node_t*) * (node->num_children-1));
             snort_free(node->children);
@@ -419,8 +419,13 @@ static int fpFinishPortGroup(SnortConfig* sc, PortGroup* pg, FastPatternConfig*
     int i;
     int rules = 0;
 
-    if ((pg == nullptr) || (fp == nullptr))
+    if (pg == nullptr)
         return -1;
+    if (fp == nullptr)
+    {
+        snort_free(pg);
+        return -1;
+    }
 
     for (i = PM_TYPE_PKT; i < PM_TYPE_MAX; i++)
     {
index 18389b592e6fb21d5aa91af37b4f7ab5261c6051..adcbc469bc31d021018f66bbd6271585b6cd8c67 100644 (file)
@@ -140,23 +140,23 @@ public:
     std::vector<Replacement> rpl;
 
     Packet* packet;
-    Packet* wire_packet;
+    Packet* wire_packet = nullptr;
     Packet* encode_packet;
     DAQ_PktHdr_t* pkth;
     uint8_t* buf;
 
-    const SnortConfig* conf;
+    const SnortConfig* conf = nullptr;
     MpseBatch searches;
     MpseStash* stash;
     OtnxMatchData* otnx;
     std::list<RegexRequest*>::iterator regex_req_it;
     SF_EVENTQ* equeue;
 
-    DataPointer file_data;
-    DataBuffer alt_data;
+    DataPointer file_data = {};
+    DataBuffer alt_data = {};
 
     uint64_t context_num;
-    uint64_t packet_number;
+    uint64_t packet_number = 0;
     ActiveRules active_rules;
     State state;
     bool check_tags;
@@ -169,13 +169,13 @@ public:
     static constexpr unsigned max_ips_id = 8;
 
 private:
-    FlowSnapshot flow;
+    FlowSnapshot flow = {};
     std::vector<IpsContextData*> data;
     std::vector<unsigned> ids_in_use;  // for indirection; FIXIT-P evaluate alternatives
     std::vector<Callback> post_callbacks;
     IpsContext* depends_on;
     IpsContext* next_to_process;
-    bool remove_gadget;
+    bool remove_gadget = false;
 };
 }
 #endif
index ce0193c74727b6c4d36af451aaab075fc649ad0f..57a0f99d09ee062172a09e2378e413605f2f8119 100644 (file)
@@ -392,11 +392,6 @@ FileCaptureState FileCapture::reserve_file(const FileInfo* file)
         head = last = fileBlock;
     }
 
-    if (!fileBlock)
-    {
-        return error_capture(FILE_CAPTURE_MEMCAP);
-    }
-
     /*Copy the last piece of file to file buffer*/
     if (save_to_file_buffer(current_data,
             current_data_len, capture_max_size) )
index b35a6b5e2393fb61355910887c85f4d2a9e15c3a..76ac8f8db46988b2d1b2346db17f7ce581cdc827 100644 (file)
@@ -97,14 +97,8 @@ FileFlows* FileFlows::get_file_flows(Flow* flow)
     {
         fd = new FileFlows(flow, fi);
         flow->set_flow_data(fd);
-    }
-    else
-        return fd;
-
-    FileConfig* fc = fi->config;
-    if (fc and fd)
-    {
-        fd->set_file_policy(&(fc->get_file_policy()));
+        if (fi->config)
+            fd->set_file_policy(&(fi->config->get_file_policy()));
     }
 
     return fd;
@@ -294,8 +288,7 @@ bool FileFlows::file_process(Packet* p, uint64_t file_id, const uint8_t* file_da
         if ((context->get_file_sig_sha256()) || !context->is_file_signature_enabled())
         {
             /* Just check file type and signature */
-            FilePosition position = SNORT_FILE_FULL;
-            continue_processing = context->process(p, file_data, data_size, position,
+            continue_processing = context->process(p, file_data, data_size, SNORT_FILE_FULL,
                     file_policy);
             if (context->processing_complete)
                 remove_processed_file_context(multi_file_processing_id);
index 8c66a9c55a3d8692da54ee811fe37894e62f91e7..333931541e7393f183f9775c89cdf24e948674f2 100644 (file)
@@ -190,7 +190,7 @@ void LogHandler::handle(DataEvent&, Flow* f)
 
     uint64_t fsize = file->get_file_size();
     if ( fsize > 0)
-        TextLog_Print(tlog, "[Size: %u] ", fsize);
+        TextLog_Print(tlog, "[Size: %lu] ", fsize);
 
     TextLog_Print(tlog, "\n");
 
index 9a2f04c3902de829bca2a6f561f7befea4b4b2a8..6a689af41bea247ea1464f060b37e57c328b520c 100644 (file)
@@ -72,11 +72,11 @@ private:
     void free_pools();
     int remove(CircularBuffer* cb, void* obj);
 
-    void** datapool; /* memory buffer */
-    uint64_t total;
-    CircularBuffer* free_list;
-    CircularBuffer* released_list;
-    size_t obj_size;
+    void** datapool = nullptr; /* memory buffer */
+    uint64_t total = 0;
+    CircularBuffer* free_list = nullptr;
+    CircularBuffer* released_list = nullptr;
+    size_t obj_size = 0;
     std::mutex pool_mutex;
 };
 
index ec11a9a92e4e4fd5131d8c64739188994b670675..75a72c8d20dbee9c901f1cf15710f56557d863f5 100644 (file)
@@ -124,26 +124,23 @@ struct CodecData
 
     /* This section will get reset before every decode() function call */
     ProtocolId next_prot_id;      /* protocol type of the next layer */
-    uint16_t lyr_len;           /* The length of the valid part layer */
-    uint16_t invalid_bytes;     /* the length of the INVALID part of this layer */
+    uint16_t lyr_len = 0;           /* The length of the valid part layer */
+    uint16_t invalid_bytes = 0;     /* the length of the INVALID part of this layer */
 
     /* Reset before each decode of packet begins */
 
     /*  Codec specific fields.  These fields are only relevant to codecs. */
-    uint32_t proto_bits;    /* protocols contained within this packet
+    uint32_t proto_bits = 0;    /* protocols contained within this packet
                                  -- will be propogated to Snort++ Packet struct*/
-    uint16_t codec_flags;   /* flags used while decoding */
-    uint8_t ip_layer_cnt;
-
-    /*  The following values have junk values after initialization */
-    uint8_t ip6_extension_count; /* initialized in cd_ipv6.cc */
-    uint8_t curr_ip6_extension;  /* initialized in cd_ipv6.cc */
-    IpProtocol ip6_csum_proto;      /* initialized in cd_ipv6.cc.  Used for IPv6 checksums */
-    bool tunnel_bypass;
-
-    CodecData(const SnortConfig* sc, ProtocolId init_prot) :
-        conf(sc), next_prot_id(init_prot), lyr_len(0), invalid_bytes(0),
-        proto_bits(0), codec_flags(0), ip_layer_cnt(0), tunnel_bypass(false)
+    uint16_t codec_flags = 0;   /* flags used while decoding */
+    uint8_t ip_layer_cnt = 0;
+
+    uint8_t ip6_extension_count = 0;
+    uint8_t curr_ip6_extension = 0;
+    IpProtocol ip6_csum_proto = IpProtocol::IP;   /* Used for IPv6 checksums */
+    bool tunnel_bypass = false;
+
+    CodecData(const SnortConfig* sc, ProtocolId init_prot) : conf(sc), next_prot_id(init_prot)
     { }
 
     bool inline is_cooked() const
index 0e64f9534cb7327395030be4df2fc6cc37e2af83..5189b010e0d4e48cf1c8e935e33b172cc94780d7 100644 (file)
@@ -152,9 +152,9 @@ protected:
     Inspector();  // internal init only at this point
 
 private:
-    const InspectApi* api;
+    const InspectApi* api = nullptr;
     std::atomic_uint* ref_count;
-    SnortProtocolId snort_protocol_id;
+    SnortProtocolId snort_protocol_id = 0;
 };
 
 // at present there is no sequencing among like types except that appid
index 255a7432189b6bb290c351e71a06a9744112ae57..f507be9f0898a38a2bacda83f910d9bbfeef8be6 100644 (file)
@@ -70,8 +70,8 @@ public:
 private:
     int log_flags = 0;
     uint8_t* buf = nullptr;
-    unsigned char* emailHdrs;
-    uint32_t log_depth;
+    unsigned char* emailHdrs = nullptr;
+    uint32_t log_depth = 0;
     uint32_t hdrs_logged;
     uint8_t* recipients = nullptr;
     uint16_t rcpts_logged;
index 8834349015b97238f8720da6f860be60cb65a90e..61da692cbcd6d166745bbf0f24bdf95e76ae599d 100644 (file)
@@ -221,7 +221,8 @@ void Active::send_reset(Packet* p, EncodeFlags ef)
         if ( (p->packet_flags & PKT_USE_DIRECT_INJECT) or
             (p->flow and p->flow->flags.use_direct_inject) )
         {
-            DIOCTL_DirectInjectReset msg = { p->daq_msg, !(ef & ENC_FLAG_FWD) };
+            DIOCTL_DirectInjectReset msg =
+                { p->daq_msg, (uint8_t)((ef & ENC_FLAG_FWD) ? DAQ_DIR_FORWARD : DAQ_DIR_REVERSE) };
             int ret = p->daq_instance->ioctl(DIOCTL_DIRECT_INJECT_RESET,
                 &msg, sizeof(msg));
             if ( ret != DAQ_SUCCESS )
@@ -296,7 +297,8 @@ uint32_t Active::send_data(
         EncodeFlags tmp_flags = flags ^ ENC_FLAG_FWD;
         if ( use_direct_inject )
         {
-            DIOCTL_DirectInjectReset msg = { p->daq_msg, !(tmp_flags & ENC_FLAG_FWD) };
+            DIOCTL_DirectInjectReset msg =
+                { p->daq_msg, (uint8_t)((tmp_flags & ENC_FLAG_FWD) ? DAQ_DIR_FORWARD : DAQ_DIR_REVERSE) };
             ret = p->daq_instance->ioctl(DIOCTL_DIRECT_INJECT_RESET,
                 &msg, sizeof(msg));
             if ( ret != DAQ_SUCCESS )
@@ -334,7 +336,8 @@ uint32_t Active::send_data(
         flags = (flags & ~ENC_FLAG_VAL);
         const DAQ_DIPayloadSegment segments[] = { {buf, blen} };
         const DAQ_DIPayloadSegment* payload[] = { &segments[0] };
-        DIOCTL_DirectInjectPayload msg = { p->daq_msg,  payload, 1, !(flags & ENC_FLAG_FWD)};
+        DIOCTL_DirectInjectPayload msg = { p->daq_msg,  payload, 1,
+            (uint8_t)((flags & ENC_FLAG_FWD) ? DAQ_DIR_FORWARD : DAQ_DIR_REVERSE) };
         ret = p->daq_instance->ioctl(DIOCTL_DIRECT_INJECT_PAYLOAD,
             &msg, sizeof(msg));
         if ( ret != DAQ_SUCCESS )
@@ -409,7 +412,8 @@ uint32_t Active::send_data(
         flags = (flags & ~ENC_FLAG_VAL) | sent;
         if ( use_direct_inject )
         {
-            DIOCTL_DirectInjectReset msg = { p->daq_msg, !(flags & ENC_FLAG_FWD) };
+            DIOCTL_DirectInjectReset msg =
+                { p->daq_msg, (uint8_t)((flags & ENC_FLAG_FWD) ? DAQ_DIR_FORWARD : DAQ_DIR_REVERSE) };
             ret = p->daq_instance->ioctl(DIOCTL_DIRECT_INJECT_RESET,
                 &msg, sizeof(msg));
             if ( ret != DAQ_SUCCESS )
index c0ecf5341f350b88fa2b804b6f90069d84e0259c..3c261380cf41537c1e2af2e60898115f136d2f8a 100644 (file)
@@ -1079,10 +1079,11 @@ void parse_rule_opt_set(
     if ( s_ignore )
         return;
 
+    assert(val);
     if ( s_capture )
     {
         s_body += opt;
-        if ( val and *val )
+        if ( *val )
         {
             s_body += " ";
             s_body += val;
index f4bb96041f23270521089f0c3caabd5407740a4b..7328e3e43ab925df8f75af88af02eb6866deb320 100644 (file)
@@ -479,7 +479,7 @@ struct RuleParseState
     string opt;
     string val;
 
-    bool tbd;
+    bool tbd = false;
 };
 
 static bool exec(
index 51dde27c4058d67ce1ddf69050615c06259d2ad7..bde9822496d0aa57c7b19e84435b8cf26b6d8eef 100644 (file)
@@ -107,10 +107,10 @@ public:
         {
             unsigned char* pc_ptr = (unsigned char*)&plx->p[i];
 
-            for ( unsigned k = 0; k < sizeof(void*); k++ )
+            for ( unsigned j = 0; j < sizeof(void*); j++ )
             {
                 hash *=  scale;
-                hash +=  pc_ptr[k];
+                hash +=  pc_ptr[j];
             }
         }
         return hash ^ hardener;
@@ -722,6 +722,9 @@ int PortTableAddObject(PortTable* p, PortObject* po)
 {
     SF_LNODE* lpos;
 
+    if ( !p )
+        return -1;
+
     /* Search for the Port Object in the input list, by address */
     for ( PortObject* pox = (PortObject*)sflist_first(p->pt_polist, &lpos);
         pox!=nullptr;
@@ -853,13 +856,18 @@ void RuleListSortUniq(SF_LIST* rl)
     int* currNode = (int*)sflist_first(rl, &pos);
 
     if ( !currNode )
+    {
+        snort_free(rlist);
         return;
+    }
 
     for ( unsigned i = 0; i < rl->count; i++ )
     {
         if (rlist[i] > lastRuleIndex)
         {
-            *currNode = lastRuleIndex = rlist[i];
+            lastRuleIndex = rlist[i];
+            if (currNode)
+                *currNode = lastRuleIndex;
             //replace the next element in place
             currNode = (int*)sflist_next(&pos);
             uniqElements++;
index 2aef07dc3a6f408fc12f26cc4b56f8ab68eb82ee..187bf62e20051a6f6c5d05ba16e95d1675c6ee79 100644 (file)
@@ -817,10 +817,6 @@ SfIpRet sfvar_parse_iplist(vartable_t* table, sfip_var_t* var,
         {
             sfip_node_t* node;
 
-            /* Skip leading commas */
-            for (; *str == ','; str++)
-                ;
-
             /* Check for a negated "any" */
             if (negation ^ neg_ip && !strcasecmp(tok, "any"))
             {