]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
threads: avoid NULL-ptr deref in thread init wait
authorVictor Julien <victor@inliniac.net>
Thu, 21 Dec 2017 09:47:52 +0000 (10:47 +0100)
committerVictor Julien <victor@inliniac.net>
Thu, 21 Dec 2017 09:47:52 +0000 (10:47 +0100)
** CID 1426745:  Null pointer dereferences  (FORWARD_NULL)
/src/tm-threads.c: 2135 in TmThreadWaitOnThreadInit()

________________________________________________________________________________________________________
*** CID 1426745:  Null pointer dereferences  (FORWARD_NULL)
/src/tm-threads.c: 2135 in TmThreadWaitOnThreadInit()
2129         struct timeval cur_ts;
2130         gettimeofday(&start_ts, NULL);
2131
2132     again:
2133         gettimeofday(&cur_ts, NULL);
2134         if ((cur_ts.tv_sec - start_ts.tv_sec) > 120) {
>>>     CID 1426745:  Null pointer dereferences  (FORWARD_NULL)
>>>     Dereferencing null pointer "tv".
2135             SCLogError(SC_ERR_THREAD_INIT, "thread \"%s\" failed to "
2136                     "initialize in time: flags %04x", tv->name,
2137                     SC_ATOMIC_GET(tv->flags));
2138             return TM_ECODE_FAILED;
2139         }
2140

src/tm-threads.c

index 3dd0cfd833d23662a50832b407ab49ae2e537d50..b71cc99fde76c4573a36002acf90f809a8b5ec00 100644 (file)
@@ -2130,14 +2130,6 @@ TmEcode TmThreadWaitOnThreadInit(void)
     gettimeofday(&start_ts, NULL);
 
 again:
-    gettimeofday(&cur_ts, NULL);
-    if ((cur_ts.tv_sec - start_ts.tv_sec) > 120) {
-        SCLogError(SC_ERR_THREAD_INIT, "thread \"%s\" failed to "
-                "initialize in time: flags %04x", tv->name,
-                SC_ATOMIC_GET(tv->flags));
-        return TM_ECODE_FAILED;
-    }
-
     SCMutexLock(&tv_root_lock);
     for (i = 0; i < TVT_MAX; i++) {
         tv = tv_root[i];
@@ -2154,6 +2146,14 @@ again:
             if (!(TmThreadsCheckFlag(tv, THV_INIT_DONE))) {
                 SCMutexUnlock(&tv_root_lock);
 
+                gettimeofday(&cur_ts, NULL);
+                if ((cur_ts.tv_sec - start_ts.tv_sec) > 120) {
+                    SCLogError(SC_ERR_THREAD_INIT, "thread \"%s\" failed to "
+                            "initialize in time: flags %04x", tv->name,
+                            SC_ATOMIC_GET(tv->flags));
+                    return TM_ECODE_FAILED;
+                }
+
                 /* sleep a little to give the thread some
                  * time to finish initialization */
                 SleepUsec(100);