mirror of
https://github.com/wesnoth/wesnoth
synced 2025-04-23 21:16:23 +00:00
accept only non-empty variable names in [set_variable(s)]...
...and wesnoth.set_variable This supposedly common problem (value of a set variable composed of the values of other variables which perhaps don't exist or are empty) causes corrupted savegames and makes :inspect fail. Hard to track on wml side; there are probably a more ways of corrupting saves via empty key or tag names.
This commit is contained in:
parent
bfa80a3fa6
commit
9ad020eea6
@ -1260,6 +1260,10 @@ WML_HANDLER_FUNCTION(set_variable, /*event_info*/, cfg)
|
||||
game_state *state_of_game = resources::state_of_game;
|
||||
|
||||
const std::string name = cfg["name"];
|
||||
if(name.empty()) {
|
||||
ERR_NG << "trying to set a variable with an empty name:\n" << cfg.get_config().debug();
|
||||
return;
|
||||
}
|
||||
config::attribute_value &var = state_of_game->get_variable(name);
|
||||
|
||||
config::attribute_value literal = cfg.get_config()["literal"]; // no $var substitution
|
||||
@ -1476,6 +1480,10 @@ WML_HANDLER_FUNCTION(set_variables, /*event_info*/, cfg)
|
||||
{
|
||||
const t_string& name = cfg["name"];
|
||||
variable_info dest(name, true, variable_info::TYPE_CONTAINER);
|
||||
if(name.empty()) {
|
||||
ERR_NG << "trying to set a variable with an empty name:\n" << cfg.get_config().debug();
|
||||
return;
|
||||
}
|
||||
|
||||
std::string mode = cfg["mode"]; // replace, append, merge, or insert
|
||||
if(mode == "extend") {
|
||||
|
@ -1385,7 +1385,8 @@ static int intf_get_variable(lua_State *L)
|
||||
*/
|
||||
static int intf_set_variable(lua_State *L)
|
||||
{
|
||||
char const *m = luaL_checkstring(L, 1);
|
||||
const std::string& m = luaL_checkstring(L, 1);
|
||||
if(m.empty()) return luaL_argerror(L, 1, "empty variable name");
|
||||
if (lua_isnoneornil(L, 2)) {
|
||||
resources::state_of_game->clear_variable(m);
|
||||
return 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user