]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
multi-tenant: fix coverity warning
authorVictor Julien <vjulien@oisf.net>
Tue, 13 Feb 2024 08:51:15 +0000 (09:51 +0100)
committerVictor Julien <victor@inliniac.net>
Wed, 14 Feb 2024 16:19:36 +0000 (17:19 +0100)
Rework locking logic to avoid the following coverity warning.

** CID 1591966:  Concurrent data access violations  (MISSING_LOCK)
/src/detect-engine-loader.c: 475 in DetectLoadersSync()

    474                     SCCtrlMutexLock(loader->tv->ctrl_mutex);
    >>>     CID 1591966:  Concurrent data access violations  (MISSING_LOCK)
    >>>     Accessing "loader->tv" without holding lock "DetectLoaderControl_.m". Elsewhere, "DetectLoaderControl_.tv" is written to with "DetectLoaderControl_.m" held 1 out of 1 times (1 of these accesses strongly imply that it is necessary).
    475                     pthread_cond_broadcast(loader->tv->ctrl_cond);
    476                     SCCtrlMutexUnlock(loader->tv->ctrl_mutex);

The warning itself is harmless.

src/detect-engine-loader.c
src/detect-engine-loader.h

index 9073c1e9c29dd2a7586e554c8470da307884f231..153c056a85b404e809787ebd938dc1a428dff97c 100644 (file)
@@ -578,8 +578,8 @@ static TmEcode DetectLoaderThreadInit(ThreadVars *t, const void *initdata, void
 
     DetectLoaderControl *loader = &loaders[ftd->instance];
     SCMutexLock(&loader->m);
-    loader->tv = t;
     SCMutexUnlock(&loader->m);
+    loader->tv = t;
 
     return TM_ECODE_OK;
 }
index 8a6f7b8f17be77d8830627ac4ad1ab8391f6a384..f43ff9a5491c11112a2dd5847b08517d1639dd14 100644 (file)
@@ -43,10 +43,14 @@ typedef struct DetectLoaderTask_ {
 
 typedef struct DetectLoaderControl_ {
     int id;
-    int result;     /* 0 for ok, error otherwise */
-    ThreadVars *tv; /* loader threads threadvars - for waking them up */
-    SCMutex m;
-    TAILQ_HEAD(, DetectLoaderTask_) task_list;
+    ThreadVars *tv; /**< loader threads threadvars - for waking them up */
+
+    /** struct to group members and mutex */
+    struct {
+        SCMutex m;  /**< mutex protects result and task_list */
+        int result; /**< 0 for ok, error otherwise */
+        TAILQ_HEAD(, DetectLoaderTask_) task_list;
+    };
 } DetectLoaderControl;
 
 int DetectLoaderQueueTask(int loader_id, LoaderFunc Func, void *func_ctx, LoaderFreeFunc FreeFunc);