diff options
author | Hans Nilsson <[email protected]> | 2019-06-28 12:54:59 +0200 |
---|---|---|
committer | Hans Nilsson <[email protected]> | 2019-06-28 14:44:15 +0200 |
commit | f3845b186191e3f479c79bd4d8b2afbdb331445c (patch) | |
tree | 009ab602532cf3875fbc512540dfa9eed60be104 /lib | |
parent | 7fe7fa3dde556b5b92522f8279d465bb52baf1f6 (diff) | |
download | otp-f3845b186191e3f479c79bd4d8b2afbdb331445c.tar.gz otp-f3845b186191e3f479c79bd4d8b2afbdb331445c.tar.bz2 otp-f3845b186191e3f479c79bd4d8b2afbdb331445c.zip |
ssh: Fix potential crash if failure in init of client
If ssh_connection_handler:init/1 failed (= returned {stop,Error})
there where no supervisors defined. That caused a Crash report
instead of a sensible logging and normal error return.
Servers are not affected of this.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ssh/src/ssh_connection_handler.erl | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/lib/ssh/src/ssh_connection_handler.erl b/lib/ssh/src/ssh_connection_handler.erl index 8f32966a12..2ce034128b 100644 --- a/lib/ssh/src/ssh_connection_handler.erl +++ b/lib/ssh/src/ssh_connection_handler.erl @@ -386,16 +386,24 @@ init_connection_handler(Role, Socket, Opts) -> D); {stop, Error} -> - Sups = ?GET_INTERNAL_OPT(supervisors, Opts), - C = #connection{system_supervisor = proplists:get_value(system_sup, Sups), - sub_system_supervisor = proplists:get_value(subsystem_sup, Sups), - connection_supervisor = proplists:get_value(connection_sup, Sups) - }, + D = try + %% Only servers have supervisorts defined in Opts + Sups = ?GET_INTERNAL_OPT(supervisors, Opts), + #connection{system_supervisor = proplists:get_value(system_sup, Sups), + sub_system_supervisor = proplists:get_value(subsystem_sup, Sups), + connection_supervisor = proplists:get_value(connection_sup, Sups) + } + of + C -> + #data{connection_state=C} + catch + _:_ -> + #data{connection_state=#connection{}} + end, gen_statem:enter_loop(?MODULE, [], {init_error,Error}, - #data{connection_state=C, - socket=Socket}) + D#data{socket=Socket}) end. |