From 2d59efb515607f52e2495716b3cbf119dc86d964 Mon Sep 17 00:00:00 2001 From: Badlop Date: Tue, 2 Nov 2010 13:51:36 +0100 Subject: [PATCH] =?utf8?q?Fix=20crash=20in=20ejabberd=5Fc2s=20when=20black?= =?utf8?q?list=20hook=20returned=20true=20(thanks=20to=20Jonas=20=C3=85dah?= =?utf8?q?l)?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 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 | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/ejabberd_c2s.erl b/src/ejabberd_c2s.erl index 260a89ad1..57baea334 100644 --- a/src/ejabberd_c2s.erl +++ b/src/ejabberd_c2s.erl @@ -196,8 +196,8 @@ init([{SockMod, Socket}, Opts]) -> %% 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 cbbdc3ce2..4adf8879e 100644 --- a/src/jlib.erl +++ b/src/jlib.erl @@ -797,5 +797,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({_,_,_,_,_,_,_,_} = Ipv6Address) -> + inet_parse:ntoa(Ipv6Address); +%% This function clause could use inet_parse too: ip_to_list({A,B,C,D}) -> lists:flatten(io_lib:format("~w.~w.~w.~w",[A,B,C,D])). -- 2.40.0