From 7999ddbc953cf40c5f0213e29847a3bd40620b65 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Fri, 4 Jun 2010 20:46:13 +0200 Subject: [PATCH] [MINOR] stream_sock: don't dereference a non-existing frontend The stream_sock accept() can be used without any frontend. Check everywhere if it exists before dereferencing it in the error path. --- src/stream_sock.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/stream_sock.c b/src/stream_sock.c index 9159796952..93e3daf591 100644 --- a/src/stream_sock.c +++ b/src/stream_sock.c @@ -1156,20 +1156,23 @@ int stream_sock_accept(int fd) case ECONNABORTED: return 0; /* nothing more to accept */ case ENFILE: - send_log(p, LOG_EMERG, - "Proxy %s reached system FD limit at %d. Please check system tunables.\n", - p->id, maxfd); + if (p) + send_log(p, LOG_EMERG, + "Proxy %s reached system FD limit at %d. Please check system tunables.\n", + p->id, maxfd); return 0; case EMFILE: - send_log(p, LOG_EMERG, - "Proxy %s reached process FD limit at %d. Please check 'ulimit-n' and restart.\n", - p->id, maxfd); + if (p) + send_log(p, LOG_EMERG, + "Proxy %s reached process FD limit at %d. Please check 'ulimit-n' and restart.\n", + p->id, maxfd); return 0; case ENOBUFS: case ENOMEM: - send_log(p, LOG_EMERG, - "Proxy %s reached system memory limit at %d sockets. Please check system tunables.\n", - p->id, maxfd); + if (p) + send_log(p, LOG_EMERG, + "Proxy %s reached system memory limit at %d sockets. Please check system tunables.\n", + p->id, maxfd); return 0; default: return 0; @@ -1184,8 +1187,10 @@ int stream_sock_accept(int fd) ret = l->accept(l, cfd, &addr); if (unlikely(ret < 0)) { /* critical error encountered, generally a resource shortage */ - EV_FD_CLR(fd, DIR_RD); - p->state = PR_STIDLE; + if (p) { + EV_FD_CLR(fd, DIR_RD); + p->state = PR_STIDLE; + } goto out_close; } else if (unlikely(ret == 0)) { -- 2.47.3