From: Michael Altizer (mialtize) Date: Fri, 23 Oct 2020 19:57:39 +0000 (+0000) Subject: Merge pull request #2574 in SNORT/snort3 from ~MIALTIZE/snort3:zero_init to master X-Git-Tag: 3.0.3-4~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c65f2b5e816278f75208bd46c45296b3833e14bd;p=thirdparty%2Fsnort3.git Merge pull request #2574 in SNORT/snort3 from ~MIALTIZE/snort3:zero_init to master Squashed commit of the following: commit d544e08894a7286b156c886e13c1df1c88b62492 Author: Michael Altizer Date: Fri Oct 23 15:10:34 2020 -0400 src: Clean up zero-initialization of arrays --- diff --git a/src/connectors/tcp_connector/tcp_connector.cc b/src/connectors/tcp_connector/tcp_connector.cc index 20940f58b..936f80558 100644 --- a/src/connectors/tcp_connector/tcp_connector.cc +++ b/src/connectors/tcp_connector/tcp_connector.cc @@ -168,7 +168,7 @@ void TcpConnector::process_receive() if (errno != EINTR) { - char error_msg[1024] = {0}; + char error_msg[1024] = { '\0' }; if (strerror_r(errno, error_msg, sizeof(error_msg)) == 0) ErrorMessage("TcpC Input Thread: Error polling on socket %d: %s\n", pfds[0].fd, error_msg); else @@ -399,7 +399,7 @@ static TcpConnector* tcp_connector_tinit_answer(TcpConnectorConfig* cfg, const c if ( listen(sfd, 10) < 0 ) { - char error_msg[1024] = {0}; + char error_msg[1024] = { '\0' }; if (strerror_r(errno, error_msg, sizeof(error_msg)) == 0) ErrorMessage("listen() failure: %s\n", error_msg); else @@ -409,7 +409,7 @@ static TcpConnector* tcp_connector_tinit_answer(TcpConnectorConfig* cfg, const c if ( (peer_sfd = accept(sfd, nullptr, nullptr )) < 0 ) { - char error_msg[1024] = {0}; + char error_msg[1024] = { '\0' }; if (strerror_r(errno, error_msg, sizeof(error_msg)) == 0) ErrorMessage("accept() failure: %s\n", error_msg); else diff --git a/src/detection/fp_create.cc b/src/detection/fp_create.cc index cbc8405a2..059a14f1c 100644 --- a/src/detection/fp_create.cc +++ b/src/detection/fp_create.cc @@ -1423,8 +1423,8 @@ static void fp_sum_service_groups(GHash* h, unsigned c[PM_TYPE_MAX]) static void fp_print_service_groups(srmm_table_t* srmm) { - unsigned to_srv[PM_TYPE_MAX] = { 0 }; - unsigned to_cli[PM_TYPE_MAX] = { 0 }; + unsigned to_srv[PM_TYPE_MAX] = { }; + unsigned to_cli[PM_TYPE_MAX] = { }; fp_sum_service_groups(srmm->to_srv, to_srv); fp_sum_service_groups(srmm->to_cli, to_cli); @@ -1460,9 +1460,9 @@ static void fp_sum_port_groups(PortTable* tab, unsigned c[PM_TYPE_MAX]) static void fp_print_port_groups(RulePortTables* port_tables) { - unsigned src[PM_TYPE_MAX] = { 0 }; - unsigned dst[PM_TYPE_MAX] = { 0 }; - unsigned any[PM_TYPE_MAX] = { 0 }; + unsigned src[PM_TYPE_MAX] = { }; + unsigned dst[PM_TYPE_MAX] = { }; + unsigned any[PM_TYPE_MAX] = { }; fp_sum_port_groups(port_tables->ip.src, src); fp_sum_port_groups(port_tables->ip.dst, dst); diff --git a/src/host_tracker/host_tracker.h b/src/host_tracker/host_tracker.h index f85aebb83..040761fcd 100644 --- a/src/host_tracker/host_tracker.h +++ b/src/host_tracker/host_tracker.h @@ -73,8 +73,8 @@ struct HostApplicationInfo { HostApplicationInfo() = default; HostApplicationInfo(const char *ver, const char *ven); - char vendor[INFO_SIZE] = { 0 }; - char version[INFO_SIZE] = { 0 }; + char vendor[INFO_SIZE] = { '\0' }; + char version[INFO_SIZE] = { '\0' }; bool visibility = true; friend class HostTracker; @@ -111,7 +111,7 @@ struct HostApplication bool inferred_appid = false; uint32_t hits = 0; uint32_t last_seen = 0; - char user[INFO_SIZE] = { 0 }; + char user[INFO_SIZE] = { '\0' }; std::vector info; std::vector> payloads; @@ -127,7 +127,7 @@ struct HostClient HostClient() = default; HostClient(AppId clientid, const char *ver, AppId ser); AppId id; - char version[INFO_SIZE] = { 0 }; + char version[INFO_SIZE] = { '\0' }; AppId service; std::vector> payloads; @@ -148,7 +148,7 @@ struct DeviceFingerprint uint32_t fpid; uint32_t fp_type; bool jail_broken; - char device[INFO_SIZE] = { 0 }; + char device[INFO_SIZE] = { '\0' }; }; enum HostType : std::uint32_t diff --git a/src/main/snort_config.cc b/src/main/snort_config.cc index d585bf189..aa4b9f2a8 100644 --- a/src/main/snort_config.cc +++ b/src/main/snort_config.cc @@ -807,7 +807,7 @@ void SnortConfig::set_tunnel_verdicts(const char* args) char* tmp, * tok; tmp = snort_strdup(args); - char* lasts = { nullptr }; + char* lasts = nullptr; tok = strtok_r(tmp, " ,", &lasts); while (tok) diff --git a/src/network_inspectors/appid/appid_debug.cc b/src/network_inspectors/appid/appid_debug.cc index 8034d61a7..9d625a9fc 100644 --- a/src/network_inspectors/appid/appid_debug.cc +++ b/src/network_inspectors/appid/appid_debug.cc @@ -110,7 +110,7 @@ void AppIdDebug::activate(const uint32_t* ip1, const uint32_t* ip2, uint16_t por snort_inet_ntop(af, &sip->u6_addr32[(af == AF_INET)? 3 : 0], sipstr, sizeof(sipstr)); snort_inet_ntop(af, &dip->u6_addr32[(af == AF_INET)? 3 : 0], dipstr, sizeof(dipstr)); - char gr_buf[32] = {0}; + char gr_buf[32] = { '\0' }; if (inter_group_flow) snprintf(gr_buf, sizeof(gr_buf), " GR=%hd-%hd", sgroup, dgroup); diff --git a/src/network_inspectors/appid/appid_http_session.h b/src/network_inspectors/appid/appid_http_session.h index ef5333cc3..fff88a14d 100644 --- a/src/network_inspectors/appid/appid_http_session.h +++ b/src/network_inspectors/appid/appid_http_session.h @@ -176,7 +176,7 @@ protected: // functions in tp_appid_utils.cc are static. Thus the public // set_field() functions in AppIdHttpSession. We do need set functions // for this array, as old pointers need to be deleted upon set(). - const std::string* meta_data[NUM_METADATA_FIELDS] = { 0 }; + const std::string* meta_data[NUM_METADATA_FIELDS] = { }; pair_t meta_offset[NUM_HTTP_FIELDS]; bool is_webdav = false; @@ -189,8 +189,8 @@ protected: int num_matches = 0; int num_scans = 0; bool skip_simple_detect = false; - int ptype_req_counts[NUM_HTTP_FIELDS] = { 0 }; - int ptype_scan_counts[NUM_HTTP_FIELDS] = { 0 }; + int ptype_req_counts[NUM_HTTP_FIELDS] = { }; + int ptype_scan_counts[NUM_HTTP_FIELDS] = { }; const TunnelDest* tun_dest = nullptr; #if RESPONSE_CODE_PACKET_THRESHHOLD unsigned response_code_packets = 0; diff --git a/src/network_inspectors/appid/appid_peg_counts.h b/src/network_inspectors/appid/appid_peg_counts.h index 1f89557de..2c0219abe 100644 --- a/src/network_inspectors/appid/appid_peg_counts.h +++ b/src/network_inspectors/appid/appid_peg_counts.h @@ -60,11 +60,11 @@ public: class AppIdDynamicPeg { public: - PegCount stats[DetectorPegs::NUM_APPID_DETECTOR_PEGS] = { 0 }; + PegCount stats[DetectorPegs::NUM_APPID_DETECTOR_PEGS] = { }; bool all_zeros() { - PegCount zeroed_peg[DetectorPegs::NUM_APPID_DETECTOR_PEGS] = { 0 }; + PegCount zeroed_peg[DetectorPegs::NUM_APPID_DETECTOR_PEGS] = { }; return !memcmp(stats, &zeroed_peg, sizeof(stats)); } diff --git a/src/network_inspectors/appid/detector_plugins/detector_imap.cc b/src/network_inspectors/appid/detector_plugins/detector_imap.cc index 4fd863f42..d719876af 100644 --- a/src/network_inspectors/appid/detector_plugins/detector_imap.cc +++ b/src/network_inspectors/appid/detector_plugins/detector_imap.cc @@ -573,7 +573,7 @@ int ImapClientDetector::validate(AppIdDiscoveryArgs& args) { const uint8_t* s = args.data; const uint8_t* end = (args.data + args.size); - char tag[IMAP_TAG_MAX_LEN + 1] = { 0 }; + char tag[IMAP_TAG_MAX_LEN + 1] = { '\0' }; #ifdef APP_ID_USES_REASSEMBLED Stream::flush_response_flush(pkt); diff --git a/src/network_inspectors/appid/detector_plugins/detector_pattern.h b/src/network_inspectors/appid/detector_plugins/detector_pattern.h index cfeae4fe0..2d82498fb 100644 --- a/src/network_inspectors/appid/detector_plugins/detector_pattern.h +++ b/src/network_inspectors/appid/detector_plugins/detector_pattern.h @@ -114,8 +114,8 @@ private: PatternService* service_port_pattern = nullptr; snort::SearchTool* tcp_pattern_matcher = nullptr; snort::SearchTool* udp_pattern_matcher = nullptr; - snort::SearchTool* tcp_port_pattern_tree[65536] = { nullptr }; - snort::SearchTool* udp_port_pattern_tree[65536] = { nullptr }; + snort::SearchTool* tcp_port_pattern_tree[65536] = { }; + snort::SearchTool* udp_port_pattern_tree[65536] = { }; }; #endif diff --git a/src/network_inspectors/appid/detector_plugins/http_url_patterns.cc b/src/network_inspectors/appid/detector_plugins/http_url_patterns.cc index fc289bc70..c1f85bdc0 100644 --- a/src/network_inspectors/appid/detector_plugins/http_url_patterns.cc +++ b/src/network_inspectors/appid/detector_plugins/http_url_patterns.cc @@ -1033,7 +1033,7 @@ static inline const char* continue_buffer_scan(const char* start, const char* en void HttpPatternMatchers::identify_user_agent(const char* start, int size, AppId& service_id, AppId& client_id, char** version) { - char temp_ver[MAX_VERSION_SIZE] = { 0 }; + char temp_ver[MAX_VERSION_SIZE] = { '\0' }; MatchedPatterns* mp = nullptr; client_agent_matcher.find_all(start, size, &http_pattern_match, false, (void*)&mp); diff --git a/src/network_inspectors/appid/detector_plugins/http_url_patterns.h b/src/network_inspectors/appid/detector_plugins/http_url_patterns.h index 406a36603..e8691793b 100644 --- a/src/network_inspectors/appid/detector_plugins/http_url_patterns.h +++ b/src/network_inspectors/appid/detector_plugins/http_url_patterns.h @@ -229,8 +229,8 @@ public: } HttpFieldIds cur_ptype; - const char* buffer[NUM_HTTP_FIELDS] = { nullptr }; - uint16_t length[NUM_HTTP_FIELDS] = { 0 }; + const char* buffer[NUM_HTTP_FIELDS] = { }; + uint16_t length[NUM_HTTP_FIELDS] = { }; std::list chp_matches[NUM_HTTP_FIELDS]; CHPMatchTally match_tally; diff --git a/src/network_inspectors/packet_tracer/packet_tracer.cc b/src/network_inspectors/packet_tracer/packet_tracer.cc index 273a7b5e7..dd28e5a29 100644 --- a/src/network_inspectors/packet_tracer/packet_tracer.cc +++ b/src/network_inspectors/packet_tracer/packet_tracer.cc @@ -278,7 +278,7 @@ void PacketTracer::add_ip_header_info(const Packet& p) actual_sip->ntop(sipstr, sizeof(sipstr)); actual_dip->ntop(dipstr, sizeof(dipstr)); - char gr_buf[32] = {0}; + char gr_buf[32] = { '\0' }; if (p.is_inter_group_flow()) snprintf(gr_buf, sizeof(gr_buf), " GR=%hd-%hd", p.pkth->ingress_group, p.pkth->egress_group); diff --git a/src/network_inspectors/rna/rna_logger.cc b/src/network_inspectors/rna/rna_logger.cc index 49c7ae89d..acabff94e 100644 --- a/src/network_inspectors/rna/rna_logger.cc +++ b/src/network_inspectors/rna/rna_logger.cc @@ -48,7 +48,7 @@ using namespace snort; #ifdef DEBUG_MSGS static inline void rna_logger_message(const RnaLoggerEvent& rle) { - char macbuf[19] = { 0 }; + char macbuf[19] = { '\0' }; if ( rle.mac ) snprintf(macbuf, 19, "%02X:%02X:%02X:%02X:%02X:%02X", rle.mac[0], rle.mac[1], rle.mac[2], rle.mac[3], rle.mac[4], rle.mac[5]); diff --git a/src/service_inspectors/ftp_telnet/ftp_print.cc b/src/service_inspectors/ftp_telnet/ftp_print.cc index 559ab0f3a..bbf6beba9 100644 --- a/src/service_inspectors/ftp_telnet/ftp_print.cc +++ b/src/service_inspectors/ftp_telnet/ftp_print.cc @@ -55,7 +55,7 @@ void print_conf_client(FTP_CLIENT_PROTO_CONF* config) FTPBounce; FTPBounce = ftp_bounce_lookup_next(config->bounce_lookup, &ret)) { - char buf[BUF_SIZE + 1] = {0}; + char buf[BUF_SIZE + 1] = { '\0' }; FTPBounce->ip.ntop(buf, BUF_SIZE); diff --git a/src/service_inspectors/http2_inspect/http2_module.cc b/src/service_inspectors/http2_inspect/http2_module.cc index 304ae1966..ac21cade1 100644 --- a/src/service_inspectors/http2_inspect/http2_module.cc +++ b/src/service_inspectors/http2_inspect/http2_module.cc @@ -56,7 +56,7 @@ THREAD_LOCAL ProfileStats Http2Module::http2_profile; ProfileStats* Http2Module::get_profile() const { return &http2_profile; } -THREAD_LOCAL PegCount Http2Module::peg_counts[PEG_COUNT__MAX] = { 0 }; +THREAD_LOCAL PegCount Http2Module::peg_counts[PEG_COUNT__MAX] = { }; bool Http2Module::begin(const char*, int, SnortConfig*) { diff --git a/src/service_inspectors/http_inspect/http_module.cc b/src/service_inspectors/http_inspect/http_module.cc index 98eba4905..0fbf441d9 100755 --- a/src/service_inspectors/http_inspect/http_module.cc +++ b/src/service_inspectors/http_inspect/http_module.cc @@ -171,7 +171,7 @@ THREAD_LOCAL ProfileStats HttpModule::http_profile; ProfileStats* HttpModule::get_profile() const { return &http_profile; } -THREAD_LOCAL PegCount HttpModule::peg_counts[PEG_COUNT_MAX] = { 0 }; +THREAD_LOCAL PegCount HttpModule::peg_counts[PEG_COUNT_MAX] = { }; bool HttpModule::begin(const char*, int, SnortConfig*) {