From 182c7b954620e9287ba2ddce9b1cbaceb1bddbaf Mon Sep 17 00:00:00 2001 From: Hans Nilsson Date: Thu, 21 Jun 2018 10:38:51 +0200 Subject: ssh: Bug fix sftp error codes Report the signal name if the signal error message is "" Do not report a return code of 0 as an error. --- lib/ssh/doc/src/ssh_sftp.xml | 8 ++++++-- lib/ssh/src/ssh_sftp.erl | 13 +++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/ssh/doc/src/ssh_sftp.xml b/lib/ssh/doc/src/ssh_sftp.xml index 129426a6d5..f367560b5f 100644 --- a/lib/ssh/doc/src/ssh_sftp.xml +++ b/lib/ssh/doc/src/ssh_sftp.xml @@ -46,9 +46,9 @@ reason() -

= atom() A description of the reason why an operation failed.

+

= atom() | string() | tuple() A description of the reason why an operation failed.

- The value is formed from the sftp error codes in the protocol-level responses as defined in + The atom() value is formed from the sftp error codes in the protocol-level responses as defined in draft-ietf-secsh-filexfer-13.txt section 9.1.

@@ -57,6 +57,10 @@ E.g. the error code SSH_FX_NO_SUCH_FILE will cause the reason() to be no_such_file.

+

The string() reason is the error information from the server in case of an exit-signal. If that information is empty, the reason is the exit signal name. +

+

The tuple() reason are other errors like the {exit_status,integer()} if the exit status is not 0. +

ssh_connection_ref() = diff --git a/lib/ssh/src/ssh_sftp.erl b/lib/ssh/src/ssh_sftp.erl index 9e1229dc85..79586141b2 100644 --- a/lib/ssh/src/ssh_sftp.erl +++ b/lib/ssh/src/ssh_sftp.erl @@ -801,13 +801,22 @@ handle_ssh_msg({ssh_cm, _, {signal, _, _}}, State) -> %% Ignore signals according to RFC 4254 section 6.9. {ok, State}; -handle_ssh_msg({ssh_cm, _, {exit_signal, ChannelId, _, Error, _}}, +handle_ssh_msg({ssh_cm, _, {exit_signal, ChannelId, Signal, Error0, _}}, State0) -> + Error = + case Error0 of + "" -> Signal; + _ -> Error0 + end, State = reply_all(State0, {error, Error}), {stop, ChannelId, State}; handle_ssh_msg({ssh_cm, _, {exit_status, ChannelId, Status}}, State0) -> - State = reply_all(State0, {error, {exit_status, Status}}), + State = + case State0 of + 0 -> State0; + _ -> reply_all(State0, {error, {exit_status, Status}}) + end, {stop, ChannelId, State}. %%-------------------------------------------------------------------- -- cgit v1.2.3 From f8cbae5c79f988de4110e4827420ad073a1c7fcb Mon Sep 17 00:00:00 2001 From: Hans Nilsson Date: Thu, 21 Jun 2018 10:39:27 +0200 Subject: ssh: Report the signal name if there is an exit-signal to sftpd --- lib/ssh/src/ssh_sftpd.erl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/ssh/src/ssh_sftpd.erl b/lib/ssh/src/ssh_sftpd.erl index a9136e5614..9e172fdb9c 100644 --- a/lib/ssh/src/ssh_sftpd.erl +++ b/lib/ssh/src/ssh_sftpd.erl @@ -137,9 +137,9 @@ handle_ssh_msg({ssh_cm, _, {signal, _, _}}, State) -> %% Ignore signals according to RFC 4254 section 6.9. {ok, State}; -handle_ssh_msg({ssh_cm, _, {exit_signal, ChannelId, _, Error, _}}, State) -> - Report = io_lib:format("Connection closed by peer ~n Error ~p~n", - [Error]), +handle_ssh_msg({ssh_cm, _, {exit_signal, ChannelId, Signal, Error, _}}, State) -> + Report = io_lib:format("Connection closed by peer signal ~p~n Error ~p~n", + [Signal,Error]), error_logger:error_report(Report), {stop, ChannelId, State}; -- cgit v1.2.3