]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MAJOR: listener: Make sure the listener exist before using it.
authorOlivier Houchard <cognet@ci0.org>
Mon, 25 Feb 2019 15:18:16 +0000 (16:18 +0100)
committerOlivier Houchard <cognet@ci0.org>
Mon, 25 Feb 2019 15:30:13 +0000 (16:30 +0100)
In listener_accept(), make sure we have a listener before attempting to
use it.
An another thread may have closed the FD meanwhile, and set fdtab[fd].owner
to NULL.
As the listener is not free'd, it is ok to attempt to accept() a new
connection even if the listener was closed. At worst the fd has been
reassigned to another connection, and accept() will fail anyway.

Many thanks to Richard Russo for reporting the problem, and suggesting the
fix.

This should be backported to 1.9 and 1.8.

src/listener.c

index e9ace41f52ec21eaff27411072906b25c402387c..4d080310d1b8e1a27c4ab1e9ee18fe1a5e776089 100644 (file)
@@ -448,8 +448,8 @@ void delete_listener(struct listener *listener)
 void listener_accept(int fd)
 {
        struct listener *l = fdtab[fd].owner;
-       struct proxy *p = l->bind_conf->frontend;
-       int max_accept = l->maxaccept ? l->maxaccept : 1;
+       struct proxy *p;
+       int max_accept;
        int expire;
        int cfd;
        int ret;
@@ -457,6 +457,10 @@ void listener_accept(int fd)
        static int accept4_broken;
 #endif
 
+       if (!l)
+               return;
+       p = l->bind_conf->frontend;
+       max_accept = l->maxaccept ? l->maxaccept : 1;
        if (HA_SPIN_TRYLOCK(LISTENER_LOCK, &l->lock))
                return;