From: Steve Chew (stechew) Date: Sun, 15 Sep 2019 16:04:45 +0000 (-0400) Subject: Merge pull request #1743 in SNORT/snort3 from ~STECHEW/snort3:prune_unis_fix to master X-Git-Tag: 3.0.0-262~37 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2ccf5e753565e792c9c63dd25ab3c0b467f90840;p=thirdparty%2Fsnort3.git Merge pull request #1743 in SNORT/snort3 from ~STECHEW/snort3:prune_unis_fix to master Squashed commit of the following: commit 544acc5afc312a7aea9c35d726171e52c2edc2d2 Author: Steve Chew Date: Thu Sep 12 21:50:36 2019 -0400 flow: When walking uni_list stop before reaching head. --- diff --git a/src/flow/flow_cache.cc b/src/flow/flow_cache.cc index 817a2f87d..28f332fa4 100644 --- a/src/flow/flow_cache.cc +++ b/src/flow/flow_cache.cc @@ -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; diff --git a/src/flow/flow_uni_list.h b/src/flow/flow_uni_list.h index 7c138e086..fd04f747d 100644 --- a/src/flow/flow_uni_list.h +++ b/src/flow/flow_uni_list.h @@ -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; }