From: kwolekr Date: Mon, 1 Dec 2014 00:01:37 +0000 (-0500) Subject: LuaSettings: Sanitize setting name strings X-Git-Tag: 0.4.11~118 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=360660947b8137fba78981932de6b503b9889e62;p=oweals%2Fminetest.git LuaSettings: Sanitize setting name strings --- diff --git a/src/script/lua_api/l_settings.cpp b/src/script/lua_api/l_settings.cpp index 13a88ee95..c2c6f009d 100644 --- a/src/script/lua_api/l_settings.cpp +++ b/src/script/lua_api/l_settings.cpp @@ -73,7 +73,7 @@ int LuaSettings::l_set(lua_State* L) std::string key = std::string(luaL_checkstring(L, 2)); const char* value = luaL_checkstring(L, 3); - o->m_settings->set(key, value); + o->m_settings->set(Settings::sanitizeString(key), value); return 1; } diff --git a/src/settings.cpp b/src/settings.cpp index 9485c7d74..34348cc06 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -63,6 +63,16 @@ Settings & Settings::operator = (const Settings &other) } +std::string Settings::sanitizeString(const std::string &value) +{ + std::string str = value; + for (const char *s = "\t\n\v\f\r\b =\""; *s; s++) + str.erase(std::remove(str.begin(), str.end(), *s), str.end()); + + return str; +} + + std::string Settings::getMultiline(std::istream &is) { std::string value; diff --git a/src/settings.h b/src/settings.h index d0bd203d3..542fae2a4 100644 --- a/src/settings.h +++ b/src/settings.h @@ -117,6 +117,7 @@ public: const std::string &end, u32 tab_depth=0); static std::string getMultiline(std::istream &is); + static std::string sanitizeString(const std::string &value); static void printValue(std::ostream &os, const std::string &name, const SettingsEntry &entry, bool is_value_multiline, u32 tab_depth=0);