mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-11 10:54:15 +02:00
Fix crashes if returning invalid arguments from graphics or ctypeDraw lua functions
This commit is contained in:
@@ -396,16 +396,26 @@ int luacon_graphicsReplacement(GRAPHICS_FUNC_ARGS, int i)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cache = luaL_optint(luacon_ci->l, -10, 0);
|
bool valid = true;
|
||||||
*pixel_mode = luaL_optint(luacon_ci->l, -9, *pixel_mode);
|
for (int i = -10; i < 0; i++)
|
||||||
*cola = luaL_optint(luacon_ci->l, -8, *cola);
|
if (!lua_isnumber(luacon_ci->l, i))
|
||||||
*colr = luaL_optint(luacon_ci->l, -7, *colr);
|
{
|
||||||
*colg = luaL_optint(luacon_ci->l, -6, *colg);
|
valid = false;
|
||||||
*colb = luaL_optint(luacon_ci->l, -5, *colb);
|
break;
|
||||||
*firea = luaL_optint(luacon_ci->l, -4, *firea);
|
}
|
||||||
*firer = luaL_optint(luacon_ci->l, -3, *firer);
|
if (valid)
|
||||||
*fireg = luaL_optint(luacon_ci->l, -2, *fireg);
|
{
|
||||||
*fireb = luaL_optint(luacon_ci->l, -1, *fireb);
|
cache = luaL_optint(luacon_ci->l, -10, 0);
|
||||||
|
*pixel_mode = luaL_optint(luacon_ci->l, -9, *pixel_mode);
|
||||||
|
*cola = luaL_optint(luacon_ci->l, -8, *cola);
|
||||||
|
*colr = luaL_optint(luacon_ci->l, -7, *colr);
|
||||||
|
*colg = luaL_optint(luacon_ci->l, -6, *colg);
|
||||||
|
*colb = luaL_optint(luacon_ci->l, -5, *colb);
|
||||||
|
*firea = luaL_optint(luacon_ci->l, -4, *firea);
|
||||||
|
*firer = luaL_optint(luacon_ci->l, -3, *firer);
|
||||||
|
*fireg = luaL_optint(luacon_ci->l, -2, *fireg);
|
||||||
|
*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