diff options
author | Johannes Weißl <[email protected]> | 2015-11-14 16:29:13 +0100 |
---|---|---|
committer | Johannes Weißl <[email protected]> | 2015-11-15 09:09:51 +0100 |
commit | 25c9d0c38d659cc00db461d760f66369e9024c54 (patch) | |
tree | 13e07712695bb4f7466da7ba5332aa8b7a537598 /lib/inets/src | |
parent | 0db6272323fd662cb43f5bb4d24f01daa8a6647d (diff) | |
download | otp-25c9d0c38d659cc00db461d760f66369e9024c54.tar.gz otp-25c9d0c38d659cc00db461d760f66369e9024c54.tar.bz2 otp-25c9d0c38d659cc00db461d760f66369e9024c54.zip |
inets: Terminate really gracefully on bad chunk
Without this fix, httpc:request/1 crashes the httpc_handler when an
invalid chunked length header is encountered (since 77acb47):
=ERROR REPORT==== 14-Nov-2015::17:19:30 ===
** Generic server <0.651.0> terminating
** Last message in was {tcp,#Port<0.5714>,
<<"HTTP/1.1 200 ok\r\nTransfer-Encoding:chunked\r\n\r\nåäö\r\n">>}
** When Server state == {state,
[...]
** Reason for termination ==
** {bad_return_value,{error,{chunk_size,"åäö"}}}
Diffstat (limited to 'lib/inets/src')
-rw-r--r-- | lib/inets/src/http_client/httpc_handler.erl | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/inets/src/http_client/httpc_handler.erl b/lib/inets/src/http_client/httpc_handler.erl index 1044cffe6f..e6dcfee818 100644 --- a/lib/inets/src/http_client/httpc_handler.erl +++ b/lib/inets/src/http_client/httpc_handler.erl @@ -1113,8 +1113,8 @@ handle_http_body(Body, #state{headers = Headers, case case_insensitive_header(TransferEnc) of "chunked" -> ?hcrt("handle_http_body - chunked", []), - case http_chunk:decode(Body, State#state.max_body_size, - State#state.max_header_size) of + try http_chunk:decode(Body, State#state.max_body_size, + State#state.max_header_size) of {Module, Function, Args} -> ?hcrt("handle_http_body - new mfa", [{module, Module}, @@ -1139,6 +1139,13 @@ handle_http_body(Body, #state{headers = Headers, handle_response(State#state{headers = NewHeaders, body = NewBody2}) end + catch throw:{error, Reason} -> + NewState = + answer_request(Request, + httpc_response:error(Request, + Reason), + State), + {stop, normal, NewState} end; Enc when Enc =:= "identity"; Enc =:= undefined -> ?hcrt("handle_http_body - identity", []), |