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] 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},