From 47dc2a9d5b2dad964f3767b4847d3aa56895dd4d Mon Sep 17 00:00:00 2001 From: reyk Date: Sun, 3 Aug 2014 21:33:27 +0000 Subject: [PATCH] Allocate http_host instead of carrying a buffer in the descriptor. --- usr.sbin/httpd/http.h | 4 ++-- usr.sbin/httpd/server_http.c | 18 +++++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/usr.sbin/httpd/http.h b/usr.sbin/httpd/http.h index 994e98b1a84..44f22ba7006 100644 --- a/usr.sbin/httpd/http.h +++ b/usr.sbin/httpd/http.h @@ -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 @@ -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; diff --git a/usr.sbin/httpd/server_http.c b/usr.sbin/httpd/server_http.c index 441328c98a0..8accdfc3c3b 100644 --- a/usr.sbin/httpd/server_http.c +++ b/usr.sbin/httpd/server_http.c @@ -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 @@ -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) && -- 2.20.1