]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
flow/manager: fix threading/locking coverity warnings
authorVictor Julien <vjulien@oisf.net>
Thu, 19 Jun 2025 12:24:18 +0000 (14:24 +0200)
committerVictor Julien <victor@inliniac.net>
Sat, 21 Jun 2025 19:32:54 +0000 (21:32 +0200)
In flow manager and recycler timed condition wait loops.

First check loop break conditions before entiring the timed wait.

CID 1638284: (#1 of 1): Indefinite wait (BAD_CHECK_OF_WAIT_COND)
dead_wait: A wait is performed without ensuring that the condition is not already satisfied while holding lock flow_manager_ctrl_mutex. This can cause a deadlock if the notification happens before the lock is acquired.

CID 1638293: (#1 of 1): Indefinite wait (BAD_CHECK_OF_WAIT_COND)
dead_wait: A wait is performed without ensuring that the condition is not already satisfied while holding lock flow_recycler_ctrl_mutex. This can cause a deadlock if the notification happens before the lock is acquired.

src/flow-manager.c

index 0b074acb253ea07ea0ad27e0befb6376125033cd..32708eefe4d85d5469a15b7183767212864ba0ba 100644 (file)
@@ -977,11 +977,12 @@ static TmEcode FlowManager(ThreadVars *th_v, void *thread_data)
             struct timespec cond_time = FROM_TIMEVAL(cond_tv);
             SCCtrlMutexLock(&flow_manager_ctrl_mutex);
             while (1) {
+                if (SC_ATOMIC_GET(flow_flags) & FLOW_EMERGENCY) {
+                    break;
+                }
                 int rc = SCCtrlCondTimedwait(
                         &flow_manager_ctrl_cond, &flow_manager_ctrl_mutex, &cond_time);
-                if (rc == ETIMEDOUT || rc < 0)
-                    break;
-                if (SC_ATOMIC_GET(flow_flags) & FLOW_EMERGENCY) {
+                if (rc == ETIMEDOUT || rc < 0) {
                     break;
                 }
             }
@@ -1153,17 +1154,17 @@ static TmEcode FlowRecycler(ThreadVars *th_v, void *thread_data)
             struct timespec cond_time = FROM_TIMEVAL(cond_tv);
             SCCtrlMutexLock(&flow_recycler_ctrl_mutex);
             while (1) {
-                int rc = SCCtrlCondTimedwait(
-                        &flow_recycler_ctrl_cond, &flow_recycler_ctrl_mutex, &cond_time);
-                if (rc == ETIMEDOUT || rc < 0) {
-                    break;
-                }
                 if (SC_ATOMIC_GET(flow_flags) & FLOW_EMERGENCY) {
                     break;
                 }
                 if (SC_ATOMIC_GET(flow_recycle_q.non_empty)) {
                     break;
                 }
+                int rc = SCCtrlCondTimedwait(
+                        &flow_recycler_ctrl_cond, &flow_recycler_ctrl_mutex, &cond_time);
+                if (rc == ETIMEDOUT || rc < 0) {
+                    break;
+                }
             }
             SCCtrlMutexUnlock(&flow_recycler_ctrl_mutex);
         }