We cannot log errors with server_close() before allocating
authorflorian <florian@openbsd.org>
Thu, 23 Apr 2015 16:59:28 +0000 (16:59 +0000)
committerflorian <florian@openbsd.org>
Thu, 23 Apr 2015 16:59:28 +0000 (16:59 +0000)
clt_log evbuffer.
server_close() calls server_log() which uses ctl_log.
Crash reported by Daniel Jakots <vigdis AT chown DOT me>, thanks!
OK benno

usr.sbin/httpd/server.c

index fe47cf4..ca67a47 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: server.c,v 1.62 2015/04/11 14:52:49 jsing Exp $       */
+/*     $OpenBSD: server.c,v 1.63 2015/04/23 16:59:28 florian Exp $     */
 
 /*
  * Copyright (c) 2006 - 2015 Reyk Floeter <reyk@openbsd.org>
@@ -852,6 +852,11 @@ server_accept(int fd, short event, void *arg)
        if ((clt = calloc(1, sizeof(*clt))) == NULL)
                goto err;
 
+       /* Pre-allocate log buffer */
+       clt->clt_log = evbuffer_new();
+       if (clt->clt_log == NULL)
+               goto err;
+
        clt->clt_s = s;
        clt->clt_fd = -1;
        clt->clt_toread = TOREAD_UNLIMITED;
@@ -899,13 +904,6 @@ server_accept(int fd, short event, void *arg)
                return;
        }
 
-       /* Pre-allocate log buffer */
-       clt->clt_log = evbuffer_new();
-       if (clt->clt_log == NULL) {
-               server_close(clt, "failed to allocate log buffer");
-               return;
-       }
-
        if (srv->srv_conf.flags & SRVFLAG_TLS) {
                event_again(&clt->clt_ev, clt->clt_s, EV_TIMEOUT|EV_READ,
                    server_accept_tls, &clt->clt_tv_start,