aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorIngela Anderton Andin <[email protected]>2012-09-26 12:18:53 +0200
committerIngela Anderton Andin <[email protected]>2012-09-26 12:18:53 +0200
commitf4654ea1d941f0067be6a6b1b18ad365eff91017 (patch)
treed1c6de57aecc980d25c48d3eb7fb42ac3a21a3e0 /lib
parent7a594dd7b4616176e774ed7e78267805d237d0a8 (diff)
parent425d8b7a53362d2c32a753d850bec14ebd57951a (diff)
downloadotp-f4654ea1d941f0067be6a6b1b18ad365eff91017.tar.gz
otp-f4654ea1d941f0067be6a6b1b18ad365eff91017.tar.bz2
otp-f4654ea1d941f0067be6a6b1b18ad365eff91017.zip
Merge branch 'ia/ssh/empty-binary/OTP-9478'
* ia/ssh/empty-binary/OTP-9478: ssh: Will not hang if you attempt to send empty binary
Diffstat (limited to 'lib')
-rw-r--r--lib/ssh/src/ssh_connection.erl17
-rw-r--r--lib/ssh/test/ssh_basic_SUITE.erl32
2 files changed, 38 insertions, 11 deletions
diff --git a/lib/ssh/src/ssh_connection.erl b/lib/ssh/src/ssh_connection.erl
index c2a7c63cbe..e3b8ebfb79 100644
--- a/lib/ssh/src/ssh_connection.erl
+++ b/lib/ssh/src/ssh_connection.erl
@@ -441,7 +441,7 @@ handle_msg(#ssh_msg_channel_window_adjust{recipient_channel = ChannelId,
{SendList, Channel} = %% TODO: Datatype 0 ?
update_send_window(Channel0#channel{send_window_size = Size + Add},
- 0, <<>>, Connection),
+ 0, undefined, Connection),
Replies = lists:map(fun({Type, Data}) ->
{connection_reply, ConnectionPid,
@@ -1073,14 +1073,15 @@ request_reply_or_data(#channel{local_id = ChannelId, user = ChannelPid},
false ->
{{channel_data, ChannelPid, Reply}, Connection}
end.
+update_send_window(Channel, _, undefined,
+ #connection{channel_cache = Cache}) ->
+ do_update_send_window(Channel, Channel#channel.send_buf, Cache);
-update_send_window(Channel0, DataType, Data,
- #connection{channel_cache = Cache}) ->
- Buf0 = if Data == <<>> ->
- Channel0#channel.send_buf;
- true ->
- Channel0#channel.send_buf ++ [{DataType, Data}]
- end,
+update_send_window(Channel, DataType, Data,
+ #connection{channel_cache = Cache}) ->
+ do_update_send_window(Channel, Channel#channel.send_buf ++ [{DataType, Data}], Cache).
+
+do_update_send_window(Channel0, Buf0, Cache) ->
{Buf1, NewSz, Buf2} = get_window(Buf0,
Channel0#channel.send_packet_size,
Channel0#channel.send_window_size),
diff --git a/lib/ssh/test/ssh_basic_SUITE.erl b/lib/ssh/test/ssh_basic_SUITE.erl
index 2ceaa9daa5..c224e5b800 100644
--- a/lib/ssh/test/ssh_basic_SUITE.erl
+++ b/lib/ssh/test/ssh_basic_SUITE.erl
@@ -110,12 +110,13 @@ all() ->
{group, rsa_pass_key},
{group, internal_error},
daemon_already_started,
- server_password_option, server_userpassword_option,
+ server_password_option,
+ server_userpassword_option,
close].
groups() ->
- [{dsa_key, [], [exec, exec_compressed, shell, known_hosts]},
- {rsa_key, [], [exec, exec_compressed, shell, known_hosts]},
+ [{dsa_key, [], [send, exec, exec_compressed, shell, known_hosts]},
+ {rsa_key, [], [send, exec, exec_compressed, shell, known_hosts]},
{dsa_pass_key, [], [pass_phrase]},
{rsa_pass_key, [], [pass_phrase]},
{internal_error, [], [internal_error]}
@@ -532,6 +533,31 @@ internal_error(Config) when is_list(Config) ->
ssh:stop_daemon(Pid).
%%--------------------------------------------------------------------
+send(doc) ->
+ ["Test ssh_connection:send/3"];
+
+send(suite) ->
+ [];
+
+send(Config) when is_list(Config) ->
+ process_flag(trap_exit, true),
+ SystemDir = filename:join(?config(priv_dir, Config), system),
+ UserDir = ?config(priv_dir, Config),
+
+ {Pid, Host, Port} = ssh_test_lib:daemon([{system_dir, SystemDir},
+ {user_dir, UserDir},
+ {failfun, fun ssh_test_lib:failfun/2}]),
+ ConnectionRef =
+ ssh_test_lib:connect(Host, Port, [{silently_accept_hosts, true},
+ {user_dir, UserDir},
+ {user_interaction, false}]),
+ {ok, ChannelId} = ssh_connection:session_channel(ConnectionRef, infinity),
+ ok = ssh_connection:send(ConnectionRef, ChannelId, <<"Data">>),
+ ok = ssh_connection:send(ConnectionRef, ChannelId, << >>),
+ ssh:stop_daemon(Pid).
+
+
+%%--------------------------------------------------------------------
close(doc) ->
["Simulate that we try to close an already closed connection"];