From 56830948e35b1cd124e83db016fccce75671752f Mon Sep 17 00:00:00 2001 From: Arne Welzel Date: Wed, 15 Nov 2023 19:41:27 +0100 Subject: [PATCH] RE_Match_State: Do not reset current_pos for every Match() call This seems like a bug: If one feeds one byte at a time, current_pos is being reset for every byte, possibly reporting the wrong offsets in the accepted_matches map. --- src/RE.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/RE.cc b/src/RE.cc index db5dad6d07..67144e9bd4 100644 --- a/src/RE.cc +++ b/src/RE.cc @@ -268,6 +268,7 @@ bool RE_Match_State::Match(const u_char* bv, int n, bool bol, bool eol, bool cle // Initialize state and copy the accepting states of the start // state into the acceptance set. + current_pos = 0; current_state = dfa->StartState(); const AcceptingSet* ac = current_state->Accept(); @@ -276,13 +277,14 @@ bool RE_Match_State::Match(const u_char* bv, int n, bool bol, bool eol, bool cle AddMatches(*ac, 0); } - else if ( clear ) + else if ( clear ) { + current_pos = 0; current_state = dfa->StartState(); + } if ( ! current_state ) return false; - current_pos = 0; size_t old_matches = accepted_matches.size();