fix: check node name, regular expression (good idea from stone)

This commit is contained in:
DDDHuang 2022-05-18 14:54:57 +08:00
parent cdb1c149e7
commit 1adb33a6a0
3 changed files with 5 additions and 16 deletions

View File

@ -31,7 +31,7 @@ File format:
* Improved resilience against autocluster partitioning during cluster * Improved resilience against autocluster partitioning during cluster
startup. [#7876] startup. [#7876]
[ekka-158](https://github.com/emqx/ekka/pull/158) [ekka-158](https://github.com/emqx/ekka/pull/158)
* Fix Added regularity (`^[0-9A-Za-z_\-]+$`) check for node names * Add regular expression check ^[0-9A-Za-z_\-]+$ for node name [#7979]
## v4.3.14 ## v4.3.14

View File

@ -488,6 +488,10 @@ fi
NAME_TYPE="$(echo "$NAME_ARG" | awk '{print $1}')" NAME_TYPE="$(echo "$NAME_ARG" | awk '{print $1}')"
NAME="$(echo "$NAME_ARG" | awk '{print $2}')" NAME="$(echo "$NAME_ARG" | awk '{print $2}')"
NODENAME="$(echo "$NAME" | awk -F'@' '{print $1}')" NODENAME="$(echo "$NAME" | awk -F'@' '{print $1}')"
if ! (echo "$NODENAME" | grep -q '^[0-9A-Za-z_\-]\+$'); then
echo "Invalid node name, should be of format '^[0-9A-Za-z_-]+$'."
exit 1
fi
export ESCRIPT_NAME="$NODENAME" export ESCRIPT_NAME="$NODENAME"
PIPE_DIR="${PIPE_DIR:-/$RUNNER_DATA_DIR/${WHOAMI}_erl_pipes/$NAME/}" PIPE_DIR="${PIPE_DIR:-/$RUNNER_DATA_DIR/${WHOAMI}_erl_pipes/$NAME/}"

View File

@ -206,21 +206,6 @@ end}.
{override_env, "NODE_NAME"} {override_env, "NODE_NAME"}
]}. ]}.
%% Node name regular expression from net_kernel:valid_name_head/1.
%% Be same with otp.
{translation, "vm_args.-name",
fun(Conf) ->
NodeName = cuttlefish:conf_get("node.name", Conf),
{Head, _Host} = lists:splitwith(fun(C) -> C =/= $@ end, NodeName),
{ok, MP} = re:compile("^[0-9A-Za-z_\\-]+$", [unicode]),
case re:run(Head, MP) of
{match, _} ->
NodeName;
nomatch ->
cuttlefish:invalid("Bad node name, expect ^[0-9A-Za-z_\\-]+$")
end
end}.
%% @doc Specify SSL Options in the file if using SSL for erlang distribution %% @doc Specify SSL Options in the file if using SSL for erlang distribution
{mapping, "node.ssl_dist_optfile", "vm_args.-ssl_dist_optfile", [ {mapping, "node.ssl_dist_optfile", "vm_args.-ssl_dist_optfile", [
{datatype, string}, {datatype, string},