aboutsummaryrefslogtreecommitdiffstats
path: root/lib/inets/src/http_server
diff options
context:
space:
mode:
authorIngela Anderton Andin <[email protected]>2015-11-04 15:14:21 +0100
committerIngela Anderton Andin <[email protected]>2015-11-11 14:43:27 +0100
commit77acb473d8f056f6f534395f131c6e45693797f0 (patch)
tree7f82d72bb7610bf40e702838c75bcec02afcf684 /lib/inets/src/http_server
parentfe1df7fc6bf050cb6c9bbd99eb9393c426b62f67 (diff)
downloadotp-77acb473d8f056f6f534395f131c6e45693797f0.tar.gz
otp-77acb473d8f056f6f534395f131c6e45693797f0.tar.bz2
otp-77acb473d8f056f6f534395f131c6e45693797f0.zip
inets: Terminate gracfully when an invalid chunked length header is encountered
Also use integer_to_list/2 and list_to_integer/2 instead of reimplementing it.
Diffstat (limited to 'lib/inets/src/http_server')
-rw-r--r--lib/inets/src/http_server/httpd_request_handler.erl10
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/inets/src/http_server/httpd_request_handler.erl b/lib/inets/src/http_server/httpd_request_handler.erl
index e5d006c1fd..143d599edb 100644
--- a/lib/inets/src/http_server/httpd_request_handler.erl
+++ b/lib/inets/src/http_server/httpd_request_handler.erl
@@ -443,7 +443,7 @@ handle_body(#state{headers = Headers, body = Body, mod = ModData} = State,
MaxHeaderSize, MaxBodySize) ->
case Headers#http_request_h.'transfer-encoding' of
"chunked" ->
- case http_chunk:decode(Body, MaxBodySize, MaxHeaderSize) of
+ try http_chunk:decode(Body, MaxBodySize, MaxHeaderSize) of
{Module, Function, Args} ->
http_transport:setopts(ModData#mod.socket_type,
ModData#mod.socket,
@@ -455,6 +455,14 @@ handle_body(#state{headers = Headers, body = Body, mod = ModData} = State,
http_chunk:handle_headers(Headers, ChunkedHeaders),
handle_response(State#state{headers = NewHeaders,
body = NewBody})
+ catch
+ throw:Error ->
+ httpd_response:send_status(ModData, 400,
+ "Bad input"),
+ Reason = io_lib:format("Chunk decoding failed: ~p~n",
+ [Error]),
+ error_log(Reason, ModData),
+ {stop, normal, State#state{response_sent = true}}
end;
Encoding when is_list(Encoding) ->
httpd_response:send_status(ModData, 501,