Skip to content

Commit

Permalink
Merge branch 'raimo/ssl/non_neg_integer-length/GH-7507/OTP-18700' int…
Browse files Browse the repository at this point in the history
…o maint-25

* raimo/ssl/non_neg_integer-length/GH-7507/OTP-18700:
  Guard against negative Length
  • Loading branch information
Erlang/OTP committed Sep 7, 2023
2 parents 5cb360d + 3936858 commit fe8f628
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/ssl/src/ssl.erl
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,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 @@ -879,13 +879,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 @@ -2870,6 +2870,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

0 comments on commit fe8f628

Please sign in to comment.