From: Willy Tarreau Date: Fri, 4 Jun 2010 18:46:13 +0000 (+0200) Subject: [MINOR] stream_sock: don't dereference a non-existing frontend X-Git-Tag: v1.5-dev8~575 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7999ddbc953cf40c5f0213e29847a3bd40620b65;p=thirdparty%2Fhaproxy.git [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. --- 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)) {