aboutsummaryrefslogtreecommitdiffstats
path: root/lib/inets/src/http_lib/http_chunk.erl
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_lib/http_chunk.erl
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_lib/http_chunk.erl')
-rw-r--r--lib/inets/src/http_lib/http_chunk.erl8
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/inets/src/http_lib/http_chunk.erl b/lib/inets/src/http_lib/http_chunk.erl
index 9476ea9f5f..c17ff6cce5 100644
--- a/lib/inets/src/http_lib/http_chunk.erl
+++ b/lib/inets/src/http_lib/http_chunk.erl
@@ -143,20 +143,22 @@ decode_size(Data = <<?CR, ?LF, ChunkRest/binary>>, HexList,
{MaxBodySize, Body,
AccLength,
MaxHeaderSize}) ->
- ChunkSize = http_util:hexlist_to_integer(lists:reverse(HexList)),
- case ChunkSize of
+ try http_util:hexlist_to_integer(lists:reverse(HexList)) of
0 -> % Last chunk, there was no data
ignore_extensions(Data, {?MODULE, decode_trailer,
[<<>>, [],[], MaxHeaderSize,
Body,
integer_to_list(AccLength)]});
- _ ->
+ ChunkSize ->
%% Note decode_data may call decode_size again if there
%% is more than one chunk, hence here is where the last parameter
%% to this function comes in.
decode_data(ChunkSize, ChunkRest, {MaxBodySize, Body,
ChunkSize + AccLength ,
MaxHeaderSize})
+ catch
+ _:_ ->
+ throw({error, {chunk_size, HexList}})
end;
decode_size(<<";", Rest/binary>>, HexList, Info) ->
%% Note ignore_extensions will call decode_size/1 again when