From: Russ Combs (rucombs) Date: Sun, 10 Mar 2019 22:26:02 +0000 (-0400) Subject: Merge pull request #1540 in SNORT/snort3 from ~RUCOMBS/snort3:fixups to master X-Git-Tag: 3.0.0-251~26 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c5e855fe883d43632d81eb08cb7929ee599a5903;p=thirdparty%2Fsnort3.git Merge pull request #1540 in SNORT/snort3 from ~RUCOMBS/snort3:fixups to master Squashed commit of the following: commit 9dfe7aef3ff54dac76c31b0d37d5ee73620a6bd8 Author: russ Date: Sun Mar 10 18:30:23 2019 -0400 memory: beware the perf_monitor, for she stealeth your numbers commit 7f761152dbe6372064cc82b0281e5b3f0b1f7a33 Author: russ Date: Sun Mar 10 18:29:50 2019 -0400 http_inspect: patch around buffer ownership confusion commit 477697e8a464eaee0749780d283c2d0057561341 Author: russ Date: Sun Mar 10 18:29:19 2019 -0400 build: fix constness warnings commit 95a5d10e1455fda40b6f297946d648b935a1d20a Author: russ Date: Sun Mar 10 18:28:52 2019 -0400 build: fix always true warning --- diff --git a/src/codecs/ip/cd_ipv6.cc b/src/codecs/ip/cd_ipv6.cc index 62a0d6299..7dadfd86d 100644 --- a/src/codecs/ip/cd_ipv6.cc +++ b/src/codecs/ip/cd_ipv6.cc @@ -471,8 +471,7 @@ void Ipv6Codec::CheckIPV6Multicast(const ip::IP6Hdr* const ip6h, const CodecData { return; // IETF consensus } - else if ((ntohl(ip6h->ip6_dst.u6_addr32[3]) >= 0x80000000) && - (ntohl(ip6h->ip6_dst.u6_addr32[3]) <= 0xFFFFFFFF)) + else if (ntohl(ip6h->ip6_dst.u6_addr32[3]) >= 0x80000000) { return; // Dynamically allocated by hosts when needed } diff --git a/src/memory/memory_cap.cc b/src/memory/memory_cap.cc index 524b26943..dcc18cbc3 100644 --- a/src/memory/memory_cap.cc +++ b/src/memory/memory_cap.cc @@ -54,7 +54,12 @@ struct Tracker { mem_stats.allocated += n; ++mem_stats.allocations; } void deallocate(size_t n) - { mem_stats.deallocated += n; ++mem_stats.deallocations; } + { + mem_stats.deallocated += n; ++mem_stats.deallocations; + assert(mem_stats.deallocated <= mem_stats.allocated); + assert(mem_stats.deallocations <= mem_stats.allocations); + assert(mem_stats.allocated or !mem_stats.allocations); + } size_t used() const { @@ -139,7 +144,7 @@ void MemoryCap::update_allocations(size_t n) n = fudge_it(n); mem_stats.total_fudge += (n - k); s_tracker.allocate(n); - auto in_use = mem_stats.allocated - mem_stats.deallocated; + auto in_use = s_tracker.used(); if ( in_use > mem_stats.max_in_use ) mem_stats.max_in_use = in_use; mp_active_context.update_allocs(n); diff --git a/src/memory/memory_module.cc b/src/memory/memory_module.cc index 9e255955b..a42367582 100644 --- a/src/memory/memory_module.cc +++ b/src/memory/memory_module.cc @@ -55,14 +55,14 @@ static MemoryCounts zero_stats = { }; const PegInfo mem_pegs[] = { - { CountType::SUM, "allocations", "total number of allocations" }, - { CountType::SUM, "deallocations", "total number of deallocations" }, - { CountType::SUM, "allocated", "total amount of memory allocated" }, - { CountType::SUM, "deallocated", "total amount of memory allocated" }, - { CountType::SUM, "reap_attempts", "attempts to reclaim memory" }, - { CountType::SUM, "reap_failures", "failures to reclaim memory" }, + { CountType::NOW, "allocations", "total number of allocations" }, + { CountType::NOW, "deallocations", "total number of deallocations" }, + { CountType::NOW, "allocated", "total amount of memory allocated" }, + { CountType::NOW, "deallocated", "total amount of memory allocated" }, + { CountType::NOW, "reap_attempts", "attempts to reclaim memory" }, + { CountType::NOW, "reap_failures", "failures to reclaim memory" }, { CountType::MAX, "max_in_use", "highest allocated - deallocated" }, - { CountType::SUM, "total_fudge", "sum of all adjustments" }, + { CountType::NOW, "total_fudge", "sum of all adjustments" }, { CountType::END, nullptr, nullptr } }; diff --git a/src/service_inspectors/http_inspect/http_inspect.cc b/src/service_inspectors/http_inspect/http_inspect.cc index 08a8db934..1e263028f 100644 --- a/src/service_inspectors/http_inspect/http_inspect.cc +++ b/src/service_inspectors/http_inspect/http_inspect.cc @@ -274,7 +274,9 @@ void HttpInspect::eval(Packet* p) } const int remove_workaround = session_data->zero_byte_workaround[source_id] ? 1 : 0; - if (!process(p->data, p->dsize - remove_workaround, p->flow, source_id, true)) + + if (!process(p->data, p->dsize - remove_workaround, p->flow, source_id, + (p->data != p->context->buf))) { DetectionEngine::disable_content(p); } diff --git a/src/stream/libtcp/stream_tcp_unit_test.cc b/src/stream/libtcp/stream_tcp_unit_test.cc index 9514ee463..c472dd6bb 100644 --- a/src/stream/libtcp/stream_tcp_unit_test.cc +++ b/src/stream/libtcp/stream_tcp_unit_test.cc @@ -109,7 +109,7 @@ Packet* get_syn_packet(Flow* flow) Packet* pkt = init_packet(flow, PKT_FROM_CLIENT); pkt->pkt = cooked_syn; - pkt->ptrs.tcph = ( tcp::TCPHdr* )( cooked_syn + 34 ); + pkt->ptrs.tcph = ( const tcp::TCPHdr* )( cooked_syn + 34 ); return pkt; } @@ -119,7 +119,7 @@ Packet* get_syn_ack_packet(Flow* flow) Packet* pkt = init_packet(flow, PKT_FROM_SERVER); pkt->pkt = cooked_syn_ack; - pkt->ptrs.tcph = ( tcp::TCPHdr* )( cooked_syn_ack + 34 ); + pkt->ptrs.tcph = ( const tcp::TCPHdr* )( cooked_syn_ack + 34 ); return pkt; } @@ -129,7 +129,7 @@ Packet* get_ack_packet(Flow* flow) Packet* pkt = init_packet(flow, PKT_FROM_CLIENT); pkt->pkt = cooked_ack; - pkt->ptrs.tcph = ( tcp::TCPHdr* )( cooked_ack + 34 ); + pkt->ptrs.tcph = ( const tcp::TCPHdr* )( cooked_ack + 34 ); return pkt; } @@ -139,7 +139,7 @@ Packet* get_fin_packet(Flow* flow) Packet* pkt = init_packet(flow, PKT_FROM_CLIENT); pkt->pkt = cooked_fin; - pkt->ptrs.tcph = ( tcp::TCPHdr* )( cooked_fin + 34 ); + pkt->ptrs.tcph = ( const tcp::TCPHdr* )( cooked_fin + 34 ); return pkt; } @@ -149,7 +149,7 @@ Packet* get_rst_packet(Flow* flow) Packet* pkt = init_packet(flow, PKT_FROM_CLIENT); pkt->pkt = cooked_rst; - pkt->ptrs.tcph = ( tcp::TCPHdr* )( cooked_rst + 34 ); + pkt->ptrs.tcph = ( const tcp::TCPHdr* )( cooked_rst + 34 ); return pkt; } @@ -159,7 +159,7 @@ Packet* get_data_packet(Flow* flow) Packet* pkt = init_packet(flow, PKT_FROM_CLIENT); pkt->pkt = cooked_data; - pkt->ptrs.tcph = ( tcp::TCPHdr* )( cooked_data + 34 ); + pkt->ptrs.tcph = ( const tcp::TCPHdr* )( cooked_data + 34 ); pkt->dsize = 42; return pkt;