From b552fbe47f4933d4e5cddfcb7b9c5d3cf59a15c9 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Tue, 25 Aug 2020 20:24:46 +0200 Subject: [PATCH] node: use regex to check node name --- include/villas/node.h | 2 ++ lib/node.cpp | 10 +++------- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/include/villas/node.h b/include/villas/node.h index 901bdafac..8c428084d 100644 --- a/include/villas/node.h +++ b/include/villas/node.h @@ -51,6 +51,8 @@ struct rtnl_cls; #endif /* WITH_NETEM */ +#define REGEX_NODE_NAME "[a-z0-9_-]{3,32}" + /** The data structure for a node. * * Every entity which exchanges messages is represented by a node. diff --git a/lib/node.cpp b/lib/node.cpp index 82071c5b4..aec2f1465 100644 --- a/lib/node.cpp +++ b/lib/node.cpp @@ -20,6 +20,7 @@ * along with this program. If not, see . *********************************************************************************/ +#include #include #include #include @@ -645,14 +646,9 @@ invalid2: bool node_is_valid_name(const char *name) { - for (const char *p = name; *p; p++) { - if (isalnum(*p) || (*p == '_') || (*p == '-')) - continue; + std::regex re(REGEX_NODE_NAME); - return false; - } - - return true; + return std::regex_match(name, re); } bool node_is_enabled(const struct node *n)