Allocate http_host instead of carrying a buffer in the descriptor.
authorreyk <reyk@openbsd.org>
Sun, 3 Aug 2014 21:33:27 +0000 (21:33 +0000)
committerreyk <reyk@openbsd.org>
Sun, 3 Aug 2014 21:33:27 +0000 (21:33 +0000)
usr.sbin/httpd/http.h
usr.sbin/httpd/server_http.c

index 994e98b..44f22ba 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: http.h,v 1.4 2014/07/25 23:23:39 reyk Exp $   */
+/*     $OpenBSD: http.h,v 1.5 2014/08/03 21:33:27 reyk Exp $   */
 
 /*
  * Copyright (c) 2012 - 2014 Reyk Floeter <reyk@openbsd.org>
@@ -151,7 +151,7 @@ struct http_descriptor {
 #define query_key               http_matchquery.kv_key
 #define query_val               http_matchquery.kv_value
 
-       char                     http_host[MAXHOSTNAMELEN];
+       char                    *http_host;
        enum httpmethod          http_method;
        int                      http_chunked;
        char                    *http_version;
index 441328c..8accdfc 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: server_http.c,v 1.32 2014/08/03 20:39:40 reyk Exp $   */
+/*     $OpenBSD: server_http.c,v 1.33 2014/08/03 21:33:27 reyk Exp $   */
 
 /*
  * Copyright (c) 2006 - 2014 Reyk Floeter <reyk@openbsd.org>
@@ -110,6 +110,10 @@ server_httpdesc_free(struct http_descriptor *desc)
                free(desc->http_version);
                desc->http_version = NULL;
        }
+       if (desc->http_host != NULL) {
+               free(desc->http_host);
+               desc->http_host = NULL;
+       }
        kv_purge(&desc->http_headers);
        desc->http_lastheader = NULL;
 }
@@ -672,6 +676,7 @@ int
 server_response(struct httpd *httpd, struct client *clt)
 {
        char                     path[MAXPATHLEN];
+       char                     hostname[MAXHOSTNAMELEN];
        struct http_descriptor  *desc   = clt->clt_desc;
        struct server           *srv = clt->clt_srv;
        struct server_config    *srv_conf = &srv->srv_conf, *location;
@@ -732,17 +737,20 @@ server_response(struct httpd *httpd, struct client *clt)
 
        if (srv_conf != NULL) {
                /* Use the actual server IP address */
-               if (server_http_host(&clt->clt_srv_ss, desc->http_host,
-                   sizeof(desc->http_host)) == NULL)
+               if (server_http_host(&clt->clt_srv_ss, hostname,
+                   sizeof(hostname)) == NULL)
                        goto fail;
        } else {
                /* Host header was valid and found */
-               if (strlcpy(desc->http_host, host->kv_value,
-                   sizeof(desc->http_host)) >= sizeof(desc->http_host))
+               if (strlcpy(hostname, host->kv_value, sizeof(hostname)) >=
+                   sizeof(hostname))
                        goto fail;
                srv_conf = clt->clt_srv_conf;
        }
 
+       if ((desc->http_host = strdup(hostname)) == NULL)
+               goto fail;
+
        /* Now search for the location */
        TAILQ_FOREACH(location, &srv->srv_hosts, entry) {
                if ((location->flags & SRVFLAG_LOCATION) &&