]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
unix-manager: fix crash when client disconnect
authorEric Leblond <eric@regit.org>
Fri, 20 Jun 2014 15:46:47 +0000 (17:46 +0200)
committerVictor Julien <victor@inliniac.net>
Mon, 23 Jun 2014 09:28:23 +0000 (11:28 +0200)
This patch fixes an issue in unix socket handling. It is possible
that a socket did disconnect when analysing a command and because
the data treatment is done in a loop on clients this was leading
to a update of the list of clients during the loop. So we need
in fact to use TAILQ_FOREACH_SAFE instead of TAILQ_FOREACH.

Reported-by: Luigi Sandon <luigi.sandon@gmail.com>
Fix-suggested-by: Luigi Sandon <luigi.sandon@gmail.com>
src/unix-manager.c

index 5fc0054bc6ce8d7524d959f39ca0cd98561c4d32..2d0a90641aa5e2ca6e1bb9e2f2623409e71d9558 100644 (file)
@@ -495,6 +495,7 @@ int UnixMain(UnixCommand * this)
     int ret;
     fd_set select_set;
     UnixClient *uclient;
+    UnixClient *tclient;
 
     /* Wait activity on the socket */
     FD_ZERO(&select_set);
@@ -526,7 +527,7 @@ int UnixMain(UnixCommand * this)
         return 1;
     }
 
-    TAILQ_FOREACH(uclient, &this->clients, next) {
+    TAILQ_FOREACH_SAFE(uclient, &this->clients, next, tclient) {
         if (FD_ISSET(uclient->fd, &select_set)) {
             UnixCommandRun(this, uclient);
         }