From 9d7d19c4569fcc04da37354636e0f5d7241278d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20B=C3=BChler?= Date: Sun, 10 Aug 2008 21:31:56 +0200 Subject: [PATCH] Fix hostname checking --- src/request.c | 16 +++++++--------- src/url_parser.h | 2 +- src/url_parser.rl | 6 +++--- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/request.c b/src/request.c index e368eb7..033a853 100644 --- a/src/request.c +++ b/src/request.c @@ -117,24 +117,24 @@ void request_validate_header(server *srv, connection *con) { return; } else if (hh) { g_string_append_len(req->uri.host, GSTR_LEN((GString*) g_queue_peek_head(&hh->values))); - if (parse_authority(&req->uri)) { + if (parse_hostname(&req->uri)) { bad_request(srv, con, 400); /* bad request */ return; } } + /* Need hostname in HTTP/1.1 */ + if (req->uri.host->len == 0 && req->http_version == HTTP_VERSION_1_1) { + bad_request(srv, con, 400); /* bad request */ + return; + } + /* may override hostname */ if (!request_parse_url(srv, con)) { bad_request(srv, con, 400); /* bad request */ return; } - /* Need hostname in HTTP/1.1 */ - if (req->uri.host->len == 0 && req->http_version == HTTP_VERSION_1_1) { - bad_request(srv, con, 400); /* bad request */ - return; - } - /* content-length */ hh = http_header_lookup_fast(req->headers, CONST_STR_LEN("content-length")); if (hh) { @@ -228,8 +228,6 @@ void request_validate_header(server *srv, connection *con) { /* the may have a content-length */ break; } - - /* TODO: check hostname */ } void physical_init(physical *phys) { diff --git a/src/url_parser.h b/src/url_parser.h index 849c945..b067cd6 100644 --- a/src/url_parser.h +++ b/src/url_parser.h @@ -5,6 +5,6 @@ #include "request.h" LI_API gboolean parse_raw_url(request_uri *uri); -LI_API gboolean parse_authority(request_uri *uri); +LI_API gboolean parse_hostname(request_uri *uri); #endif diff --git a/src/url_parser.rl b/src/url_parser.rl index 3592a0b..ac308d2 100644 --- a/src/url_parser.rl +++ b/src/url_parser.rl @@ -68,7 +68,7 @@ URI = scheme "://" (authority >mark %save_authority) URI_path; parse_URI := URI | ("*" >mark %save_path) | URI_path; - parse_Authority := authority; + parse_Hostname := (host >mark_host %save_host) ( ":" port )?; write data; }%% @@ -89,7 +89,7 @@ gboolean parse_raw_url(request_uri *uri) { return (cs >= url_parser_first_final); } -gboolean parse_authority(request_uri *uri) { +gboolean parse_hostname(request_uri *uri) { const char *p, *pe, *eof; const char *mark = NULL, *host_mark = NULL; int cs; @@ -99,7 +99,7 @@ gboolean parse_authority(request_uri *uri) { eof = pe = uri->authority->str + uri->authority->len; %% write init nocs; - cs = url_parser_en_parse_Authority; + cs = url_parser_en_parse_Hostname; %% write exec;