diff options
author | David Wragg <dpw@lshift.net> | 2010-05-24 15:26:40 +0100 |
---|---|---|
committer | David Wragg <dpw@lshift.net> | 2010-05-24 15:26:40 +0100 |
commit | a3b4a146ab6c8964c2ae2b4d1cfe4a4c81cf4cea (patch) | |
tree | 3d6ae30ae6040aa36bd6752707deb2b6481b8770 | |
parent | 1e74500391dc74f3b8ddef467cbfb6c0e6820e35 (diff) | |
download | rabbitmq-server-bug22774.tar.gz |
Handle quoted node names by parsing with erl_scan:stringbug22774
If the node name contains characters which cannot be used in a simple
Erlang atom (e.g. a hyphen), then pid_to_string will quote it;
e.g. <'rabbit@centos5-64'.51.0>. If in string_to_pid we try to
convert the node name part back to an atom with list_to_atom, the
quotes will be included in the resulting atom
(e.g. '\'rabbit@centos5-64\'') and so the two functions will not be
inverses. So use erl_scan to parse the node name instead, to recover
an atom that exactly matches the original.
-rw-r--r-- | src/rabbit_misc.erl | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/rabbit_misc.erl b/src/rabbit_misc.erl index 723b818b..9a911ab1 100644 --- a/src/rabbit_misc.erl +++ b/src/rabbit_misc.erl @@ -537,18 +537,24 @@ pid_to_string(Pid) when is_pid(Pid) -> %% inverse of above string_to_pid(Str) -> + Err = {error, {invalid_pid_syntax, Str}}, %% The \ before the trailing $ is only there to keep emacs %% font-lock from getting confused. case re:run(Str, "^<(.*)\\.([0-9]+)\\.([0-9]+)>\$", [{capture,all_but_first,list}]) of {match, [NodeStr, IdStr, SerStr]} -> - %% turn the triple into a pid - see pid_to_string - <<131,NodeEnc/binary>> = term_to_binary(list_to_atom(NodeStr)), + %% the NodeStr atom might be quoted, so we have to parse + %% it rather than doing a simple list_to_atom + NodeAtom = case erl_scan:string(NodeStr) of + {ok, [{atom, _, X}], _} -> X; + {error, _, _} -> throw(Err) + end, + <<131,NodeEnc/binary>> = term_to_binary(NodeAtom), Id = list_to_integer(IdStr), Ser = list_to_integer(SerStr), binary_to_term(<<131,103,NodeEnc/binary,Id:32,Ser:32,0:8>>); nomatch -> - throw({error, {invalid_pid_syntax, Str}}) + throw(Err) end. version_compare(A, B, lte) -> |