]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MINOR] stream_sock: don't dereference a non-existing frontend
authorWilly Tarreau <w@1wt.eu>
Fri, 4 Jun 2010 18:46:13 +0000 (20:46 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 14 Jun 2010 08:53:18 +0000 (10:53 +0200)
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

index 915979695251416a6310ce3b8f4751a283b2d92f..93e3daf591169a36521a9dd014ef52cf8f554d8d 100644 (file)
@@ -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)) {