From 9bb4d92717d8570def89596843954b7bfb464835 Mon Sep 17 00:00:00 2001 From: jacob1 Date: Mon, 2 Jun 2014 00:41:25 -0400 Subject: [PATCH] prevent setting invalid wall types with lua --- src/lua/LegacyLuaAPI.cpp | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/lua/LegacyLuaAPI.cpp b/src/lua/LegacyLuaAPI.cpp index 8f2ed2e1da..9eff92304c 100644 --- a/src/lua/LegacyLuaAPI.cpp +++ b/src/lua/LegacyLuaAPI.cpp @@ -1226,15 +1226,16 @@ int luatpt_set_property(lua_State* l) int luatpt_set_wallmap(lua_State* l) { int nx, ny, acount; - int x1, y1, width, height; - float value; + int x1, y1, width, height, wallType; acount = lua_gettop(l); x1 = abs(luaL_optint(l, 1, 0)); y1 = abs(luaL_optint(l, 2, 0)); width = abs(luaL_optint(l, 3, XRES/CELL)); height = abs(luaL_optint(l, 4, YRES/CELL)); - value = (float)luaL_optint(l, acount, 0); + wallType = luaL_optint(l, acount, 0); + if (wallType < 0 || wallType >= UI_WALLCOUNT) + return luaL_error(l, "Unrecognised wall number %d", wallType); if (acount == 5) //Draw rect { @@ -1249,7 +1250,7 @@ int luatpt_set_wallmap(lua_State* l) for (nx = x1; nxbmap[ny][nx] = value; + luacon_sim->bmap[ny][nx] = wallType; } } else //Set point @@ -1258,20 +1259,15 @@ int luatpt_set_wallmap(lua_State* l) x1 = (XRES/CELL); if(y1 > (YRES/CELL)) y1 = (YRES/CELL); - luacon_sim->bmap[y1][x1] = value; + luacon_sim->bmap[y1][x1] = wallType; } return 0; } int luatpt_get_wallmap(lua_State* l) { - int nx, ny, acount; - int x1, y1, width, height; - float value; - acount = lua_gettop(l); - - x1 = abs(luaL_optint(l, 1, 0)); - y1 = abs(luaL_optint(l, 2, 0)); + int x1 = abs(luaL_optint(l, 1, 0)); + int y1 = abs(luaL_optint(l, 2, 0)); if(x1 > (XRES/CELL) || y1 > (YRES/CELL)) return luaL_error(l, "Out of range");