From e0aa686ff2fb65382407d32e02d16f5a8afda7ab Mon Sep 17 00:00:00 2001 From: Jyrki Vesterinen Date: Fri, 18 Jan 2019 21:36:18 +0200 Subject: [PATCH] Disallow creating variables with invalid WML tag names (fixes #3877) Variables are saved as WML elements, and as such, variable names must also be valid WML tag names. --- src/variable_info_detail.hpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/variable_info_detail.hpp b/src/variable_info_detail.hpp index b6bb990a56d9..03777358540e 100644 --- a/src/variable_info_detail.hpp +++ b/src/variable_info_detail.hpp @@ -41,6 +41,11 @@ class vi_policy_const static const config& get_child_at(const config& cfg, const std::string& key, int index) { assert(index >= 0); + + if(!config::valid_tag(key)) { + throw invalid_variablename_exception(); + } + // cfg.child_or_empty does not support index parameter if(const config& child = cfg.child(key, index)) { return child; @@ -63,6 +68,11 @@ class vi_policy_create static config& get_child_at(config& cfg, const std::string& key, int index) { assert(index >= 0); + + if (!config::valid_tag(key)) { + throw invalid_variablename_exception(); + } + // the 'create_if_not_existent' logic. while(static_cast(cfg.child_count(key)) <= index) { cfg.add_child(key);