Browse Source

Make sure an incorrect port returns a 400 error

Loïc Hoguin 12 years ago
parent
commit
7ff2a62585
2 changed files with 4 additions and 1 deletions
  1. 3 1
      src/cowboy_protocol.erl
  2. 1 0
      test/http_SUITE.erl

+ 3 - 1
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,
 			request(B, State, M, P, Q, F, Version, Headers,
 				<<>>, default_port(Transport:name()));
 				<<>>, default_port(Transport:name()));
 		{_, RawHost} ->
 		{_, RawHost} ->
-			case parse_host(RawHost, <<>>) of
+			case catch parse_host(RawHost, <<>>) of
+				{'EXIT', _} ->
+					error_terminate(400, State);
 				{Host, undefined} ->
 				{Host, undefined} ->
 					request(B, State, M, P, Q, F, Version, Headers,
 					request(B, State, M, P, Q, F, Version, Headers,
 						Host, default_port(Transport:name()));
 						Host, default_port(Transport:name()));

+ 1 - 0
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, "\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/1.1\r\nHost: ninenines.eu\r\n\r\n"},
 		{400, "GET http://proxy/ HTTP/1.1\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},
 		{505, ResponsePacket},
 		{408, "GET / HTTP/1.1\r\n"},
 		{408, "GET / HTTP/1.1\r\n"},
 		{408, "GET / HTTP/1.1\r\nHost: localhost"},
 		{408, "GET / HTTP/1.1\r\nHost: localhost"},