From cdb1c149e76588c89f0766a54fe8628aa53c9198 Mon Sep 17 00:00:00 2001 From: DDDHuang <44492639+DDDHuang@users.noreply.github.com> Date: Wed, 18 May 2022 13:59:24 +0800 Subject: [PATCH 1/2] fix(conf): check node name, otp regular expression --- CHANGES-4.3.md | 1 + priv/emqx.schema | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/CHANGES-4.3.md b/CHANGES-4.3.md index 8b509fe17..e8c4804b3 100644 --- a/CHANGES-4.3.md +++ b/CHANGES-4.3.md @@ -31,6 +31,7 @@ File format: * Improved resilience against autocluster partitioning during cluster startup. [#7876] [ekka-158](https://github.com/emqx/ekka/pull/158) +* Fix Added regularity (`^[0-9A-Za-z_\-]+$`) check for node names ## v4.3.14 diff --git a/priv/emqx.schema b/priv/emqx.schema index 4d7b1beda..5a352993a 100644 --- a/priv/emqx.schema +++ b/priv/emqx.schema @@ -206,6 +206,21 @@ end}. {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 {mapping, "node.ssl_dist_optfile", "vm_args.-ssl_dist_optfile", [ {datatype, string}, From 1adb33a6a0a89c19c1c8f0b4ad44e3435d8c0921 Mon Sep 17 00:00:00 2001 From: DDDHuang <44492639+DDDHuang@users.noreply.github.com> Date: Wed, 18 May 2022 14:54:57 +0800 Subject: [PATCH 2/2] fix: check node name, regular expression (good idea from stone) --- CHANGES-4.3.md | 2 +- bin/emqx | 4 ++++ priv/emqx.schema | 15 --------------- 3 files changed, 5 insertions(+), 16 deletions(-) diff --git a/CHANGES-4.3.md b/CHANGES-4.3.md index e8c4804b3..61ce7c232 100644 --- a/CHANGES-4.3.md +++ b/CHANGES-4.3.md @@ -31,7 +31,7 @@ File format: * Improved resilience against autocluster partitioning during cluster startup. [#7876] [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 diff --git a/bin/emqx b/bin/emqx index bcb7622a0..a3843ec7e 100755 --- a/bin/emqx +++ b/bin/emqx @@ -488,6 +488,10 @@ fi NAME_TYPE="$(echo "$NAME_ARG" | awk '{print $1}')" NAME="$(echo "$NAME_ARG" | awk '{print $2}')" 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" PIPE_DIR="${PIPE_DIR:-/$RUNNER_DATA_DIR/${WHOAMI}_erl_pipes/$NAME/}" diff --git a/priv/emqx.schema b/priv/emqx.schema index 5a352993a..4d7b1beda 100644 --- a/priv/emqx.schema +++ b/priv/emqx.schema @@ -206,21 +206,6 @@ end}. {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 {mapping, "node.ssl_dist_optfile", "vm_args.-ssl_dist_optfile", [ {datatype, string},