]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
util/interval-tree: fix coverity warning 10600/head
authorShivani Bhardwaj <shivani@oisf.net>
Fri, 8 Mar 2024 08:36:31 +0000 (14:06 +0530)
committerVictor Julien <victor@inliniac.net>
Fri, 8 Mar 2024 21:01:30 +0000 (22:01 +0100)
Fix Coverity warning

** CID 1592992:  Incorrect expression  (COPY_PASTE_ERROR)
/src/util-port-interval-tree.c: 255 in SCPortIntervalFindOverlaps()

________________________________________________________________________________________________________
*** CID 1592992:  Incorrect expression  (COPY_PASTE_ERROR)
/src/util-port-interval-tree.c: 255 in SCPortIntervalFindOverlaps()
249                      * will be sorted, insert any new ports to the end of the list
250                      * and avoid walking the entire list */
251                     if (*list == NULL) {
252                         *list = new_port;
253                         (*list)->last = new_port;
254                     } else if (((*list)->last->port != new_port->port) &&
>>>     CID 1592992:  Incorrect expression  (COPY_PASTE_ERROR)
>>>     "port" in "(*list)->last->port2 != new_port->port" looks like a copy-paste error.
255                                ((*list)->last->port2 != new_port->port)) {
256                         DEBUG_VALIDATE_BUG_ON(new_port->port < (*list)->last->port);
257                         (*list)->last->next = new_port;
258                         new_port->prev = (*list)->last;
259                         (*list)->last = new_port;
260                     } else {

The code does not generate two port ranges that are same other than the
cases where port == port2 which is why it worked so far. Fix it.

Bug 6839

src/util-port-interval-tree.c

index d4c770585a6eeb2640f7996b4fb39af2949248e9..57fe1094f204b42666dbb30ac8187ef7e8929758 100644 (file)
@@ -252,7 +252,7 @@ static void SCPortIntervalFindOverlaps(DetectEngineCtx *de_ctx, const uint16_t p
                     *list = new_port;
                     (*list)->last = new_port;
                 } else if (((*list)->last->port != new_port->port) &&
-                           ((*list)->last->port2 != new_port->port)) {
+                           ((*list)->last->port2 != new_port->port2)) {
                     DEBUG_VALIDATE_BUG_ON(new_port->port < (*list)->last->port);
                     (*list)->last->next = new_port;
                     new_port->prev = (*list)->last;