]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
detect/pcre: avoid infinite loop after negated pcre
authorPhilippe Antoine <pantoine@oisf.net>
Tue, 28 Jan 2025 14:02:45 +0000 (15:02 +0100)
committerVictor Julien <vjulien@oisf.net>
Mon, 17 Mar 2025 19:56:43 +0000 (20:56 +0100)
Ticket: 7526

The usage of negated pcre, followed by other relative payload
content keywords could lead to an infinite loop.

This is because regular (not negated) pcre can test multiple
occurences, but negated pcre should be tried only once.

(cherry picked from commit b14c67cbdf25fa6c7ffe0d04ddf3ebe67b12b50b)

src/detect-engine-content-inspection.c

index 06b18283fb52337399131d2d526d9a2d0a01c69f..3ca221235cf3440de1b57324b22e0e931f2e8166 100644 (file)
@@ -450,7 +450,6 @@ uint8_t DetectEngineContentInspection(DetectEngineCtx *de_ctx, DetectEngineThrea
             if (r == 0) {
                 goto no_match;
             }
-
             if (!(pe->flags & DETECT_PCRE_RELATIVE_NEXT)) {
                 SCLogDebug("no relative match coming up, so this is a match");
                 goto match;
@@ -473,6 +472,11 @@ uint8_t DetectEngineContentInspection(DetectEngineCtx *de_ctx, DetectEngineThrea
             if (det_ctx->discontinue_matching)
                 goto no_match;
 
+            if (prev_offset == 0) {
+                // This happens for negated PCRE
+                // We do not search for another occurrence of this pcre
+                SCReturnInt(0);
+            }
             det_ctx->buffer_offset = prev_buffer_offset;
             det_ctx->pcre_match_start_offset = prev_offset;
         } while (1);