]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #1743 in SNORT/snort3 from ~STECHEW/snort3:prune_unis_fix to master
authorSteve Chew (stechew) <stechew@cisco.com>
Sun, 15 Sep 2019 16:04:45 +0000 (12:04 -0400)
committerSteve Chew (stechew) <stechew@cisco.com>
Sun, 15 Sep 2019 16:04:45 +0000 (12:04 -0400)
Squashed commit of the following:

commit 544acc5afc312a7aea9c35d726171e52c2edc2d2
Author: Steve Chew <stechew@cisco.com>
Date:   Thu Sep 12 21:50:36 2019 -0400

    flow: When walking uni_list stop before reaching head.

src/flow/flow_cache.cc
src/flow/flow_uni_list.h

index 817a2f87d6a9bf74e0ed95a5e34c99e904a1a3f0..28f332fa442f9f8ac8d5afbe68fad17677a250a1 100644 (file)
@@ -236,7 +236,7 @@ unsigned FlowCache::prune_unis(PktType pkt_type)
     while ( (uni_list->get_count() > max_uni) && flow && (pruned < cleanup_flows) )
     {
         Flow* prune_me = flow;
-        flow = prune_me->prev;
+        flow = uni_list->get_prev(prune_me);
 
         if ( prune_me->was_blocked() )
             continue;
index 7c138e0864f0ffedeb25853a79dfe96e7ef13b0a..fd04f747d9a38eaf6402695d912bf5a17e7bde20 100644 (file)
@@ -31,9 +31,10 @@ public:
     {
         head = new snort::Flow;
         tail = new snort::Flow;
-
         head->next = tail;
         tail->prev = head;
+        head->prev = nullptr;
+        tail->next = nullptr;
     }
 
     ~FlowUniList()
@@ -44,13 +45,10 @@ public:
 
     void link_uni(snort::Flow* flow)
     {
-
         flow->next = head->next;
         flow->prev = head;
-
         head->next->prev = flow;
         head->next = flow;
-
         ++count;
     }
 
@@ -59,16 +57,22 @@ public:
         if ( !flow->next )
             return;
 
-        --count;
-
         flow->next->prev = flow->prev;
         flow->prev->next = flow->next;
-
         flow->next = flow->prev = nullptr;
+        --count;
+
     }
 
     snort::Flow* get_oldest_uni()
-    { return tail->prev; }
+    {
+        return ( tail->prev != head ) ? tail->prev : nullptr;
+    }
+
+    snort::Flow* get_prev(snort::Flow* flow)
+    {
+        return ( flow->prev != head ) ? flow->prev : nullptr;
+    }
 
     unsigned get_count() const
     { return count; }