mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-12 03:14:04 +02:00
Fix crashes if returning invalid arguments from graphics or ctypeDraw lua functions
This commit is contained in:
@@ -395,6 +395,15 @@ int luacon_graphicsReplacement(GRAPHICS_FUNC_ARGS, int i)
|
|||||||
lua_pop(luacon_ci->l, 1);
|
lua_pop(luacon_ci->l, 1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
bool valid = true;
|
||||||
|
for (int i = -10; i < 0; i++)
|
||||||
|
if (!lua_isnumber(luacon_ci->l, i))
|
||||||
|
{
|
||||||
|
valid = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (valid)
|
||||||
{
|
{
|
||||||
cache = luaL_optint(luacon_ci->l, -10, 0);
|
cache = luaL_optint(luacon_ci->l, -10, 0);
|
||||||
*pixel_mode = luaL_optint(luacon_ci->l, -9, *pixel_mode);
|
*pixel_mode = luaL_optint(luacon_ci->l, -9, *pixel_mode);
|
||||||
@@ -406,6 +415,7 @@ int luacon_graphicsReplacement(GRAPHICS_FUNC_ARGS, int i)
|
|||||||
*firer = luaL_optint(luacon_ci->l, -3, *firer);
|
*firer = luaL_optint(luacon_ci->l, -3, *firer);
|
||||||
*fireg = luaL_optint(luacon_ci->l, -2, *fireg);
|
*fireg = luaL_optint(luacon_ci->l, -2, *fireg);
|
||||||
*fireb = luaL_optint(luacon_ci->l, -1, *fireb);
|
*fireb = luaL_optint(luacon_ci->l, -1, *fireb);
|
||||||
|
}
|
||||||
lua_pop(luacon_ci->l, 10);
|
lua_pop(luacon_ci->l, 10);
|
||||||
}
|
}
|
||||||
return cache;
|
return cache;
|
||||||
|
@@ -2701,7 +2701,8 @@ static bool luaCtypeDrawWrapper(CTYPEDRAW_FUNC_ARGS)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ret = luaL_optinteger(luacon_ci->l, -1, 0);
|
if (lua_isboolean(luacon_ci->l, -1))
|
||||||
|
ret = lua_toboolean(luacon_ci->l, -1);
|
||||||
lua_pop(luacon_ci->l, 1);
|
lua_pop(luacon_ci->l, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2864,7 +2865,7 @@ int LuaScriptInterface::elements_property(lua_State * l)
|
|||||||
{
|
{
|
||||||
lua_gr_func[id].Assign(3);
|
lua_gr_func[id].Assign(3);
|
||||||
}
|
}
|
||||||
else if (lua_type(l, 3) == LUA_TBOOLEAN && !lua_toboolean(l, -1))
|
else if (lua_type(l, 3) == LUA_TBOOLEAN && !lua_toboolean(l, 3))
|
||||||
{
|
{
|
||||||
lua_gr_func[id].Clear();
|
lua_gr_func[id].Clear();
|
||||||
luacon_sim->elements[id].Graphics = NULL;
|
luacon_sim->elements[id].Graphics = NULL;
|
||||||
@@ -2879,7 +2880,7 @@ int LuaScriptInterface::elements_property(lua_State * l)
|
|||||||
lua_cd_func[id].Assign(3);
|
lua_cd_func[id].Assign(3);
|
||||||
luacon_sim->elements[id].CtypeDraw = luaCtypeDrawWrapper;
|
luacon_sim->elements[id].CtypeDraw = luaCtypeDrawWrapper;
|
||||||
}
|
}
|
||||||
else if (lua_type(l, 3) == LUA_TBOOLEAN && !lua_toboolean(l, -1))
|
else if (lua_type(l, 3) == LUA_TBOOLEAN && !lua_toboolean(l, 3))
|
||||||
{
|
{
|
||||||
lua_cd_func[id].Clear();
|
lua_cd_func[id].Clear();
|
||||||
luacon_sim->elements[id].CtypeDraw = nullptr;
|
luacon_sim->elements[id].CtypeDraw = nullptr;
|
||||||
|
Reference in New Issue
Block a user