From 39e563a0e0a8e3a71fec8f5a1f5d4dfb0a3425f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Thu, 27 May 2010 14:23:48 +0200 Subject: dist_utils: Eliminate crash when list_to_existing_atom/1 fails In the following scenario list_to_existing_atom/1 may crash during handshake: Start a node in one window: erl -sname adam@localhost Start another node in another window: erl -sname bertil In this node, ping the first node (use the actual hostname in the command): net:ping(adam@hostname). There will be an error report similar to: =ERROR REPORT==== 27-May-2010::15:03:14 === Error in process <0.40.0> on node 'bertil@hostname' with exit value: {badarg,[{erlang,list_to_existing_atom, ["adam@localhost"]},{dist_util,recv_challenge,1},{dist_util,handshake_we_started,1}]} Eliminate the crash and the error report by catching the call to list_to_existing_atom/1 and do a clean shutdown if it fails. --- lib/kernel/src/dist_util.erl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/kernel/src/dist_util.erl b/lib/kernel/src/dist_util.erl index a2937d60b8..8fc4934f1f 100644 --- a/lib/kernel/src/dist_util.erl +++ b/lib/kernel/src/dist_util.erl @@ -564,7 +564,7 @@ recv_challenge(#hs_data{socket=Socket,other_node=Node, case Recv(Socket, 0, infinity) of {ok,[$n,V1,V0,Fl1,Fl2,Fl3,Fl4,CA3,CA2,CA1,CA0 | Ns]} -> Flags = ?u32(Fl1,Fl2,Fl3,Fl4), - case {list_to_existing_atom(Ns),?u16(V1,V0)} of + try {list_to_existing_atom(Ns),?u16(V1,V0)} of {Node,Version} -> Challenge = ?u32(CA3,CA2,CA1,CA0), ?trace("recv: node=~w, challenge=~w version=~w\n", @@ -572,6 +572,9 @@ recv_challenge(#hs_data{socket=Socket,other_node=Node, {Flags,Challenge}; _ -> ?shutdown(no_node) + catch + error:badarg -> + ?shutdown(no_node) end; _ -> ?shutdown(no_node) -- cgit v1.2.3