]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
detect/port: fix grouping of ports w gaps
authorShivani Bhardwaj <shivani@oisf.net>
Thu, 21 Mar 2024 08:45:39 +0000 (14:15 +0530)
committerVictor Julien <victor@inliniac.net>
Fri, 24 May 2024 17:11:03 +0000 (19:11 +0200)
If a single port happens before a range port, the port groups created
were incorrect. Fix it to use smarter range check.

For example, given,
80:80 - SGH1
100:120 - SGH2

Range created should be
80:80 - SGH1
100:120 - SGH2

Bug 6881

(cherry picked from commit 7d937db5cb87e0ab2ed3c435db109c11ed95e676)

src/detect-engine-build.c

index ecd2ef65ca9c20d7ec6b24dda1297687d6f65027..4970a7ee7b440b414e79f2a630a73caf883b3bb2 100644 (file)
@@ -1453,7 +1453,13 @@ static inline int CreatePortList(DetectEngineCtx *de_ctx, const uint8_t *unique_
                 port = port2 + 1;
             } else if (p1 && p1->single) {
                 SCPortIntervalFindOverlappingRanges(de_ctx, port, port, &it->tree, list);
-                port = port + 1;
+                if ((port2 > port + 1)) {
+                    SCPortIntervalFindOverlappingRanges(
+                            de_ctx, port + 1, port2 - 1, &it->tree, list);
+                    port = port2;
+                } else {
+                    port = port + 1;
+                }
             } else if (p2->single) {
                 /* If port2 is boundary and less or equal to port + 1, create a range
                  * keeping the boundary away as it is single port */