diff options
author | Ingela Anderton Andin <[email protected]> | 2014-12-01 09:24:14 +0100 |
---|---|---|
committer | Ingela Anderton Andin <[email protected]> | 2014-12-01 09:24:14 +0100 |
commit | 7d717fb60d33280f4d18f0cbeb73dc90140b5040 (patch) | |
tree | 77af37646b675c1ed2fb7365fd0336454f3a5e13 /lib/ssh/src | |
parent | 948c140f207fdae5016780229a8ad803aa80e372 (diff) | |
parent | 029663735a8358d8b1698e39299b972183e3bf91 (diff) | |
download | otp-7d717fb60d33280f4d18f0cbeb73dc90140b5040.tar.gz otp-7d717fb60d33280f4d18f0cbeb73dc90140b5040.tar.bz2 otp-7d717fb60d33280f4d18f0cbeb73dc90140b5040.zip |
Merge branch 'ia/ssh/gracefull-termination/OTP-12185' into maint
* ia/ssh/gracefull-termination/OTP-12185:
ssh: Gracefully handle bad input
Diffstat (limited to 'lib/ssh/src')
-rw-r--r-- | lib/ssh/src/ssh_connection_handler.erl | 50 |
1 files changed, 30 insertions, 20 deletions
diff --git a/lib/ssh/src/ssh_connection_handler.erl b/lib/ssh/src/ssh_connection_handler.erl index 8b7c4a5f80..fdb9d3b3e6 100644 --- a/lib/ssh/src/ssh_connection_handler.erl +++ b/lib/ssh/src/ssh_connection_handler.erl @@ -1299,9 +1299,9 @@ generate_event(<<?BYTE(Byte), _/binary>> = Msg, StateName, end; generate_event(Msg, StateName, State0, EncData) -> - Event = ssh_message:decode(Msg), - State = generate_event_new_state(State0, EncData), try + Event = ssh_message:decode(Msg), + State = generate_event_new_state(State0, EncData), case Event of #ssh_msg_kexinit{} -> %% We need payload for verification later. @@ -1315,7 +1315,7 @@ generate_event(Msg, StateName, State0, EncData) -> #ssh_msg_disconnect{code = ?SSH_DISCONNECT_PROTOCOL_ERROR, description = "Encountered unexpected input", language = "en"}, - handle_disconnect(DisconnectMsg, State) + handle_disconnect(DisconnectMsg, State0) end. @@ -1475,25 +1475,35 @@ handle_ssh_packet(Length, StateName, #state{decoded_data_buffer = DecData0, ssh_params = Ssh0, transport_protocol = _Protocol, socket = _Socket} = State0) -> - {Ssh1, DecData, EncData, Mac} = - ssh_transport:unpack(EncData0, Length, Ssh0), - SshPacket = <<DecData0/binary, DecData/binary>>, - case ssh_transport:is_valid_mac(Mac, SshPacket, Ssh1) of - true -> - PacketData = ssh_transport:msg_data(SshPacket), - {Ssh1, Msg} = ssh_transport:decompress(Ssh1, PacketData), - generate_event(Msg, StateName, - State0#state{ssh_params = Ssh1, - %% Important to be set for - %% next_packet - decoded_data_buffer = <<>>}, EncData); - false -> - DisconnectMsg = + try + {Ssh1, DecData, EncData, Mac} = + ssh_transport:unpack(EncData0, Length, Ssh0), + SshPacket = <<DecData0/binary, DecData/binary>>, + case ssh_transport:is_valid_mac(Mac, SshPacket, Ssh1) of + true -> + PacketData = ssh_transport:msg_data(SshPacket), + {Ssh1, Msg} = ssh_transport:decompress(Ssh1, PacketData), + generate_event(Msg, StateName, + State0#state{ssh_params = Ssh1, + %% Important to be set for + %% next_packet + decoded_data_buffer = <<>>}, + EncData); + false -> + DisconnectMsg = + #ssh_msg_disconnect{code = ?SSH_DISCONNECT_PROTOCOL_ERROR, + description = "Bad mac", + language = "en"}, + handle_disconnect(DisconnectMsg, State0) + end + catch _:_ -> + Disconnect = #ssh_msg_disconnect{code = ?SSH_DISCONNECT_PROTOCOL_ERROR, - description = "Bad mac", + description = "Bad input", language = "en"}, - handle_disconnect(DisconnectMsg, State0) - end. + handle_disconnect(Disconnect, State0) + end. + handle_disconnect(DisconnectMsg, State) -> handle_disconnect(own, DisconnectMsg, State). |