diff options
author | Jo-Philipp Wich <jo@mein.io> | 2020-09-17 10:53:03 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2020-09-17 10:54:57 +0200 |
commit | a15ca46d283e0f7ae84650b4526cf138e6e7e886 (patch) | |
tree | b908d9aae0e1edc7b645cf6b9dd5746991c1f859 | |
parent | 5e1affb4ed61df9e01df979573fe05c0e2c84ea0 (diff) |
eval: sanitize variable names
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
-rw-r--r-- | eval.c | 19 |
1 files changed, 18 insertions, 1 deletions
@@ -1530,6 +1530,23 @@ ut_globals_init(struct ut_state *state, struct json_object *scope) json_object_object_add(scope, "REQUIRE_SEARCH_PATH", arr); } +static void +ut_register_variable(struct json_object *scope, const char *key, struct json_object *val) +{ + char *name = strdup(key); + char *p; + + if (!name) + return; + + for (p = name; *p; p++) + if (!isalnum(*p) && *p != '_') + *p = '_'; + + json_object_object_add(scope, name, val); + free(name); +} + enum ut_error_type ut_run(struct ut_state *state, struct json_object *env) { @@ -1547,7 +1564,7 @@ ut_run(struct ut_state *state, struct json_object *env) if (env) { json_object_object_foreach(env, key, val) - json_object_object_add(scope, key, val); + ut_register_variable(scope, key, val); } ut_globals_init(state, scope); |