read_schematic_replacements: ensure fields are strings (#5726)
authorLoïc Blot <nerzhul@users.noreply.github.com>
Mon, 8 May 2017 18:43:03 +0000 (20:43 +0200)
committerGitHub <noreply@github.com>
Mon, 8 May 2017 18:43:03 +0000 (20:43 +0200)
* read_schematic_replacements: ensure fields are strings

add a type check before reading strings on read_schematic_replacements deserializer

* throw LuaError instead of asserting the whole client

src/script/lua_api/l_mapgen.cpp

index 6d3171df969ba89b36c5e103365b0633ae10f966..32eb7af8480ec3cf7a6c4bbbd4a80d38ebd6377c 100644 (file)
@@ -325,14 +325,22 @@ void read_schematic_replacements(lua_State *L, int index, StringMap *replace_nam
 
                if (lua_istable(L, -1)) { // Old {{"x", "y"}, ...} format
                        lua_rawgeti(L, -1, 1);
+                       if (!lua_isstring(L, -1))
+                               throw LuaError("schematics: replace_from field is not a string");
                        replace_from = lua_tostring(L, -1);
                        lua_pop(L, 1);
 
                        lua_rawgeti(L, -1, 2);
+                       if (!lua_isstring(L, -1))
+                               throw LuaError("schematics: replace_to field is not a string");
                        replace_to = lua_tostring(L, -1);
                        lua_pop(L, 1);
                } else { // New {x = "y", ...} format
+                       if (!lua_isstring(L, -2))
+                               throw LuaError("schematics: replace_from field is not a string");
                        replace_from = lua_tostring(L, -2);
+                       if (!lua_isstring(L, -1))
+                               throw LuaError("schematics: replace_to field is not a string");
                        replace_to = lua_tostring(L, -1);
                }