]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #1540 in SNORT/snort3 from ~RUCOMBS/snort3:fixups to master
authorRuss Combs (rucombs) <rucombs@cisco.com>
Sun, 10 Mar 2019 22:26:02 +0000 (18:26 -0400)
committerRuss Combs (rucombs) <rucombs@cisco.com>
Sun, 10 Mar 2019 22:26:02 +0000 (18:26 -0400)
Squashed commit of the following:

commit 9dfe7aef3ff54dac76c31b0d37d5ee73620a6bd8
Author: russ <rucombs@cisco.com>
Date:   Sun Mar 10 18:30:23 2019 -0400

    memory: beware the perf_monitor, for she stealeth your numbers

commit 7f761152dbe6372064cc82b0281e5b3f0b1f7a33
Author: russ <rucombs@cisco.com>
Date:   Sun Mar 10 18:29:50 2019 -0400

    http_inspect: patch around buffer ownership confusion

commit 477697e8a464eaee0749780d283c2d0057561341
Author: russ <rucombs@cisco.com>
Date:   Sun Mar 10 18:29:19 2019 -0400

    build: fix constness warnings

commit 95a5d10e1455fda40b6f297946d648b935a1d20a
Author: russ <rucombs@cisco.com>
Date:   Sun Mar 10 18:28:52 2019 -0400

    build: fix always true warning

src/codecs/ip/cd_ipv6.cc
src/memory/memory_cap.cc
src/memory/memory_module.cc
src/service_inspectors/http_inspect/http_inspect.cc
src/stream/libtcp/stream_tcp_unit_test.cc

index 62a0d6299d5dc7892ece841e5af5ac3d3cec31d6..7dadfd86d3b93196c9c0b5ad9fd8b1e9ebdc0953 100644 (file)
@@ -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
         }
index 524b269430451fb266e6c27b941a9def973b3da1..dcc18cbc33624a484693c5dadd6948b306e80ffa 100644 (file)
@@ -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);
index 9e255955b90a240a6bd426e81d1e398ed4b743ee..a423675825f5d8585969e748e6197781a3c90307 100644 (file)
@@ -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 }
 };
 
index 08a8db934286b96aa4a91e056a2c022f4d326b5f..1e263028f1094504060a5d55fd7d5e412ff455b4 100644 (file)
@@ -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);
     }
index 9514ee4630c223987bda932f1ca58a68a3801474..c472dd6bb0bd09857a4c666f3ee3eaa27ae52ffb 100644 (file)
@@ -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;