From 81546f327061085c5a59c4c6f40924fa9993ff4a Mon Sep 17 00:00:00 2001 From: Badlop Date: Tue, 2 Nov 2010 14:04:10 +0100 Subject: [PATCH] =?UTF-8?q?Fix=20crash=20in=20ejabberd=5Fc2s=20when=20blac?= =?UTF-8?q?klist=20hook=20returned=20true=20(thanks=20to=20Jonas=20=C3=85d?= =?UTF-8?q?ahl)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cause of the crash jlib:ip_to_list/1 only supports IP tuples using the form {N1,N2,N3,N4} which is not the case when IPv6 is enabled. --- src/ejabberd_c2s.erl | 4 ++-- src/jlib.erl | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ejabberd_c2s.erl b/src/ejabberd_c2s.erl index 40c5a515f..975f79423 100644 --- a/src/ejabberd_c2s.erl +++ b/src/ejabberd_c2s.erl @@ -243,8 +243,8 @@ init([{SockMod, Socket}, Opts, FSMLimitOpts]) -> %% Check if IP is blacklisted: case is_ip_blacklisted(IP) of true -> - ?INFO_MSG("Connection attempt from blacklisted IP: ~s", - [jlib:ip_to_list(IP)]), + ?INFO_MSG("Connection attempt from blacklisted IP: ~s (~w)", + [jlib:ip_to_list(IP), IP]), {stop, normal}; false -> Socket1 = diff --git a/src/jlib.erl b/src/jlib.erl index 930434e83..fad376684 100644 --- a/src/jlib.erl +++ b/src/jlib.erl @@ -387,8 +387,8 @@ e(X) -> exit({bad_encode_base64_token, X}). %% Convert Erlang inet IP to list ip_to_list({IP, _Port}) -> ip_to_list(IP); -ip_to_list({A,B,C,D}) -> - lists:flatten(io_lib:format("~w.~w.~w.~w",[A,B,C,D])). +ip_to_list(IpTuple) when is_tuple(IpTuple) -> + inet_parse:ntoa(IpTuple). % -------------------------------------------------------------------- % Compat layer.