mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
node: check for validity of node name
This commit is contained in:
parent
4c6aca75da
commit
b0d497eee4
3 changed files with 19 additions and 0 deletions
|
@ -201,6 +201,8 @@ struct node_type * node_type(struct node *n);
|
|||
|
||||
struct memory_type * node_memory_type(struct node *n, struct memory_type *parent);
|
||||
|
||||
int node_is_valid_name(const char *name);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
13
lib/node.c
13
lib/node.c
|
@ -21,6 +21,7 @@
|
|||
*********************************************************************************/
|
||||
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include <villas/node/config.h>
|
||||
#include <villas/hook.h>
|
||||
|
@ -766,3 +767,15 @@ invalid2:
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int node_is_valid_name(const char *name)
|
||||
{
|
||||
for (const char *p = name; *p; p++) {
|
||||
if (isalnum(*p) || (*p == '_') || (*p == '-'))
|
||||
continue;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -217,6 +217,10 @@ int SuperNode::parseJson(json_t *j)
|
|||
struct node_type *nt;
|
||||
const char *type;
|
||||
|
||||
ret = node_is_valid_name(name);
|
||||
if (ret)
|
||||
throw RuntimeError("Invalid name for node: {}", name);
|
||||
|
||||
ret = json_unpack_ex(json_node, &err, 0, "{ s: s }", "type", &type);
|
||||
if (ret)
|
||||
throw JsonError(err, "Failed to parse node");
|
||||
|
|
Loading…
Add table
Reference in a new issue