Skip to content

Commit 34728f7

Browse files
Merge pull request #7972 from rabbitmq/mergify/bp/v3.12.x/pr-7961
Special case "unknown" for IP address (backport #7961)
2 parents 8d8403c + 69fb0fe commit 34728f7

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

deps/rabbit_common/src/rabbit_data_coercion.erl

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,27 @@ to_binary(Val) when is_integer(Val) -> integer_to_binary(Val);
1818
to_binary(Val) when is_function(Val) -> list_to_binary(io_lib:format("~w", [Val]));
1919
to_binary(Val) -> Val.
2020

21-
-spec to_list(Val :: integer() | list() | binary() | atom() | map()) -> list().
21+
-spec to_list(Val :: integer() | list() | binary() | atom() | map() | inet:ip_address()) -> list().
2222
to_list(Val) when is_list(Val) -> Val;
2323
to_list(Val) when is_map(Val) -> maps:to_list(Val);
2424
to_list(Val) when is_atom(Val) -> atom_to_list(Val);
2525
to_list(Val) when is_binary(Val) -> binary_to_list(Val);
26-
to_list(Val) when is_integer(Val) -> integer_to_list(Val).
26+
to_list(Val) when is_integer(Val) -> integer_to_list(Val);
27+
to_list({V0, V1, V2, V3}=Val) when (is_integer(V0) andalso (V0 >=0 andalso V0 =< 255)) andalso
28+
(is_integer(V1) andalso (V1 >=0 andalso V1 =< 255)) andalso
29+
(is_integer(V2) andalso (V2 >=0 andalso V2 =< 255)) andalso
30+
(is_integer(V3) andalso (V3 >=0 andalso V3 =< 255)) ->
31+
io_lib:format("~w", [Val]);
32+
to_list({V0, V1, V2, V3, V4, V5, V6, V7}=Val)
33+
when (is_integer(V0) andalso (V0 >=0 andalso V0 =< 65535)) andalso
34+
(is_integer(V1) andalso (V1 >=0 andalso V1 =< 65535)) andalso
35+
(is_integer(V2) andalso (V2 >=0 andalso V2 =< 65535)) andalso
36+
(is_integer(V3) andalso (V3 >=0 andalso V3 =< 65535)) andalso
37+
(is_integer(V4) andalso (V4 >=0 andalso V4 =< 65535)) andalso
38+
(is_integer(V5) andalso (V5 >=0 andalso V5 =< 65535)) andalso
39+
(is_integer(V6) andalso (V6 >=0 andalso V6 =< 65535)) andalso
40+
(is_integer(V7) andalso (V7 >=0 andalso V7 =< 65535)) ->
41+
io_lib:format("~w", [Val]).
2742

2843
-spec to_atom(Val :: atom() | list() | binary()) -> atom().
2944
to_atom(Val) when is_atom(Val) -> Val;

deps/rabbitmq_auth_backend_http/src/rabbit_auth_backend_http.erl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,14 @@ join_tags(Tags) ->
194194
Strings = [rabbit_data_coercion:to_list(T) || T <- Tags],
195195
string:join(Strings, " ").
196196

197-
-spec parse_peeraddr(inet:ip_address()) -> string().
197+
-spec parse_peeraddr(inet:ip_address() | unknown) -> string().
198+
parse_peeraddr(unknown) ->
199+
rabbit_data_coercion:to_list(unknown);
198200
parse_peeraddr(PeerAddr) ->
199201
handle_inet_ntoa_peeraddr(inet:ntoa(PeerAddr), PeerAddr).
200202

201-
-spec handle_inet_ntoa_peeraddr({'error', term()} | string(), inet:ip_address()) -> string().
203+
-spec handle_inet_ntoa_peeraddr({'error', term()} | string(), inet:ip_address() | unknown) -> string().
202204
handle_inet_ntoa_peeraddr({error, einval}, PeerAddr) ->
203-
rabbit_data_coercion:to_list(io_lib:format("~w", [PeerAddr]));
205+
rabbit_data_coercion:to_list(PeerAddr);
204206
handle_inet_ntoa_peeraddr(PeerAddrStr, _PeerAddr0) ->
205207
PeerAddrStr.

0 commit comments

Comments
 (0)