aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ssl/src
diff options
context:
space:
mode:
authorRaimo Niskanen <[email protected]>2019-07-02 14:12:18 +0200
committerRaimo Niskanen <[email protected]>2019-07-02 14:12:18 +0200
commit54e8284d883b11a83ec48edb41c9a15d657bae8e (patch)
tree1f31a2dc323eea78aed9ea0ded747325921feddd /lib/ssl/src
parent7fe7fa3dde556b5b92522f8279d465bb52baf1f6 (diff)
downloadotp-54e8284d883b11a83ec48edb41c9a15d657bae8e.tar.gz
otp-54e8284d883b11a83ec48edb41c9a15d657bae8e.tar.bz2
otp-54e8284d883b11a83ec48edb41c9a15d657bae8e.zip
Fix extracting 0 bytes from queue
Diffstat (limited to 'lib/ssl/src')
-rw-r--r--lib/ssl/src/ssl_connection.erl2
-rw-r--r--lib/ssl/src/tls_record.erl11
2 files changed, 9 insertions, 4 deletions
diff --git a/lib/ssl/src/ssl_connection.erl b/lib/ssl/src/ssl_connection.erl
index fbbe0a49c8..af9f0cbf3a 100644
--- a/lib/ssl/src/ssl_connection.erl
+++ b/lib/ssl/src/ssl_connection.erl
@@ -670,6 +670,8 @@ read_application_dist_data(DHandle, Front0, BufferSize, Rear0, Bin0) ->
end
end.
+iovec_from_front(0, Front, Rear, Acc) ->
+ {lists:reverse(Acc),Front,Rear};
iovec_from_front(Size, [], Rear, Acc) ->
iovec_from_front(Size, lists:reverse(Rear), [], Acc);
iovec_from_front(Size, [Bin|Front], Rear, Acc) ->
diff --git a/lib/ssl/src/tls_record.erl b/lib/ssl/src/tls_record.erl
index 38022030ee..afbf95948d 100644
--- a/lib/ssl/src/tls_record.erl
+++ b/lib/ssl/src/tls_record.erl
@@ -489,16 +489,19 @@ validate_tls_record_length(Versions, {_,Size0,_} = Q0, Acc, Type, Version, Lengt
end.
-binary_from_front(SplitSize, {Front,Size,Rear}) ->
+binary_from_front(0, Q) ->
+ {<<>>, Q};
+binary_from_front(SplitSize, {Front,Size,Rear}) when SplitSize =< Size ->
binary_from_front(SplitSize, Front, Size, Rear, []).
%%
+%% SplitSize > 0 and there is at least SplitSize bytes buffered in Front and Rear
binary_from_front(SplitSize, [], Size, [_] = Rear, Acc) ->
- %% Optimize a simple case
+ %% Optimize a simple case - avoid lists:reverse/1
binary_from_front(SplitSize, Rear, Size, [], Acc);
-binary_from_front(SplitSize, [], Size, Rear, Acc) ->
+binary_from_front(SplitSize, [], Size, [_|_] = Rear, Acc) ->
binary_from_front(SplitSize, lists:reverse(Rear), Size, [], Acc);
binary_from_front(SplitSize, [Bin|Front], Size, Rear, []) ->
- %% Optimize a frequent case
+ %% Optimize the frequent case when the accumulator is empty
BinSize = byte_size(Bin),
if
SplitSize < BinSize ->