Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guard against negative Length in ssl:recv/3 #7526

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions lib/ssl/src/ssl.erl
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ send(#sslsocket{pid = {ListenSocket, #config{transport_info = Info}}}, Data) ->
%%--------------------------------------------------------------------
-spec recv(SslSocket, Length) -> {ok, Data} | {error, reason()} when
SslSocket :: sslsocket(),
Length :: integer(),
Length :: non_neg_integer(),
Data :: binary() | list() | HttpPacket,
HttpPacket :: any().

Expand All @@ -888,13 +888,15 @@ recv(Socket, Length) ->

-spec recv(SslSocket, Length, Timeout) -> {ok, Data} | {error, reason()} when
SslSocket :: sslsocket(),
Length :: integer(),
Length :: non_neg_integer(),
Data :: binary() | list() | HttpPacket,
Timeout :: timeout(),
HttpPacket :: any().

recv(#sslsocket{pid = [Pid|_]}, Length, Timeout) when is_pid(Pid),
(is_integer(Timeout) andalso Timeout >= 0) or (Timeout == infinity)->
recv(#sslsocket{pid = [Pid|_]}, Length, Timeout)
when is_pid(Pid) andalso
(is_integer(Length) andalso Length >= 0) andalso
((is_integer(Timeout) andalso Timeout >= 0) orelse Timeout == infinity) ->
ssl_gen_statem:recv(Pid, Length, Timeout);
recv(#sslsocket{pid = {dtls,_}}, _, _) ->
{error,enotconn};
Expand Down
4 changes: 4 additions & 0 deletions lib/ssl/test/ssl_api_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -3720,6 +3720,10 @@ controlling_process_result(Socket, Pid, Msg) ->
controller_dies_result(_Socket, _Pid, _Msg) ->
receive Result -> Result end.
send_recv_result_timeout_client(Socket) ->
try ssl:recv(Socket, 11, not_infinity) catch error : function_clause -> ok end,
try ssl:recv(Socket, 11, -1) catch error : function_clause -> ok end,
try ssl:recv(Socket, not_integer, 500) catch error : function_clause -> ok end,
try ssl:recv(Socket, -1, 500) catch error : function_clause -> ok end,
{error, timeout} = ssl:recv(Socket, 11, 500),
{error, timeout} = ssl:recv(Socket, 11, 0),
ssl:send(Socket, "Hello world"),
Expand Down
Loading