From 7ff2a62585258e65830e80d5ac0abb75b9c1cf0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Sat, 22 Dec 2012 16:45:04 +0100 Subject: Make sure an incorrect port returns a 400 error --- src/cowboy_protocol.erl | 4 +++- test/http_SUITE.erl | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cowboy_protocol.erl b/src/cowboy_protocol.erl index 0d15f32..7ab66a9 100644 --- a/src/cowboy_protocol.erl +++ b/src/cowboy_protocol.erl @@ -379,7 +379,9 @@ request(B, State=#state{transport=Transport}, M, P, Q, F, Version, Headers) -> request(B, State, M, P, Q, F, Version, Headers, <<>>, default_port(Transport:name())); {_, RawHost} -> - case parse_host(RawHost, <<>>) of + case catch parse_host(RawHost, <<>>) of + {'EXIT', _} -> + error_terminate(400, State); {Host, undefined} -> request(B, State, M, P, Q, F, Version, Headers, Host, default_port(Transport:name())); diff --git a/test/http_SUITE.erl b/test/http_SUITE.erl index dfb9496..c90e585 100644 --- a/test/http_SUITE.erl +++ b/test/http_SUITE.erl @@ -366,6 +366,7 @@ The document has moved {400, "\r\n\r\n\r\n\r\n\r\n\r\n"}, {400, "GET / HTTP/1.1\r\nHost: ninenines.eu\r\n\r\n"}, {400, "GET http://proxy/ HTTP/1.1\r\n\r\n"}, + {400, "GET / HTTP/1.1\r\nHost: localhost:bad_port\r\n\r\n"}, {505, ResponsePacket}, {408, "GET / HTTP/1.1\r\n"}, {408, "GET / HTTP/1.1\r\nHost: localhost"}, -- cgit v1.2.3