[syslinux:master] core/http: Append port number to Host field if needed

syslinux-bot for Gene Cumm gene.cumm at gmail.com
Sat Oct 10 07:03:04 PDT 2015


Commit-ID:  d04e8b2ffd982e58111e03e413136f3b7ec4b9dc
Gitweb:     http://www.syslinux.org/commit/d04e8b2ffd982e58111e03e413136f3b7ec4b9dc
Author:     Gene Cumm <gene.cumm at gmail.com>
AuthorDate: Sat, 10 Oct 2015 10:00:02 -0400
Committer:  Gene Cumm <gene.cumm at gmail.com>
CommitDate: Sat, 10 Oct 2015 10:00:02 -0400

core/http: Append port number to Host field if needed

HTTP/1.1 header Host must contain the port number if not default for the
protocol.  Host isn't a part of HTTP/1.0 but let's implement it right.

Reported-By: Michael DeCandia <michael.decandia at gmail.com>
Signed-off-by: Gene Cumm <gene.cumm at gmail.com>

---
 core/fs/pxe/http.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/core/fs/pxe/http.c b/core/fs/pxe/http.c
index bd18f3c..f5f49e2 100644
--- a/core/fs/pxe/http.c
+++ b/core/fs/pxe/http.c
@@ -211,12 +211,25 @@ void http_open(struct url_info *url, int flags, struct inode *inode,
     header_bytes += snprintf(header_buf + header_bytes,
 			     header_len - header_bytes,
 			     " HTTP/1.0\r\n"
-			     "Host: %s\r\n"
+			     "Host: %s",
+			     url->host);
+    if (header_bytes >= header_len)
+	goto fail;		/* Buffer overflow */
+    if (url->port != HTTP_PORT) {
+	header_bytes += snprintf(header_buf + header_bytes,
+			     header_len - header_bytes,
+			     ":%d", url->port);
+	if (header_bytes >= header_len)
+	    goto fail;		/* Buffer overflow */
+    }
+    header_bytes += snprintf(header_buf + header_bytes,
+			     header_len - header_bytes,
+			     "\r\n"
 			     "User-Agent: Syslinux/" VERSION_STR "\r\n"
 			     "Connection: close\r\n"
 			     "%s"
 			     "\r\n",
-			     url->host, cookie_buf ? cookie_buf : "");
+			     cookie_buf ? cookie_buf : "");
     if (header_bytes >= header_len)
 	goto fail;		/* Buffer overflow */
 


More information about the Syslinux-commits mailing list