]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
threads: don't crash in slow shutdown 3157/head
authorVictor Julien <victor@inliniac.net>
Mon, 15 Jan 2018 17:16:47 +0000 (18:16 +0100)
committerVictor Julien <victor@inliniac.net>
Mon, 15 Jan 2018 17:16:57 +0000 (18:16 +0100)
If TmThreadDrainPacketThreads would take more than 60 seconds, the wait
loop that follows it would reach 'timeout' condition immediately. This
would lead to a null ptr deref of 'tv'.

Fix by not counting the TmThreadDrainPacketThreads and also not doing
the null ptr deref in any case.

src/tm-threads.c

index 25fef956a8c722c135bf61e3d00d6175f8810b94..07b2bf1b4f2bed1443406aaadef86a782a2f144a 100644 (file)
@@ -1673,15 +1673,17 @@ void TmThreadDisablePacketThreads(void)
     ThreadVars *tv = NULL;
     struct timeval start_ts;
     struct timeval cur_ts;
-    gettimeofday(&start_ts, NULL);
 
     /* first drain all packet threads of their packets */
     TmThreadDrainPacketThreads();
+
+    gettimeofday(&start_ts, NULL);
 again:
     gettimeofday(&cur_ts, NULL);
     if ((cur_ts.tv_sec - start_ts.tv_sec) > 60) {
         FatalError(SC_ERR_FATAL, "Engine unable to disable detect "
-                "thread - \"%s\". Killing engine", tv->name);
+                "thread - \"%s\". Killing engine",
+                tv ? tv->name : "<unknown>");
     }
 
     SCMutexLock(&tv_root_lock);