mirror of
https://github.com/minetest/minetest.git
synced 2024-11-23 16:13:46 +01:00
Fix secure io.open without mode
This commit is contained in:
parent
0d1c9598a0
commit
9e10f9f49a
@ -525,14 +525,19 @@ int ScriptApiSecurity::sl_g_require(lua_State *L)
|
|||||||
|
|
||||||
int ScriptApiSecurity::sl_io_open(lua_State *L)
|
int ScriptApiSecurity::sl_io_open(lua_State *L)
|
||||||
{
|
{
|
||||||
|
bool with_mode = lua_gettop(L) > 1;
|
||||||
|
|
||||||
luaL_checktype(L, 1, LUA_TSTRING);
|
luaL_checktype(L, 1, LUA_TSTRING);
|
||||||
const char *path = lua_tostring(L, 1);
|
const char *path = lua_tostring(L, 1);
|
||||||
CHECK_SECURE_PATH(L, path);
|
CHECK_SECURE_PATH(L, path);
|
||||||
|
|
||||||
push_original(L, "io", "open");
|
push_original(L, "io", "open");
|
||||||
lua_pushvalue(L, 1);
|
lua_pushvalue(L, 1);
|
||||||
lua_pushvalue(L, 2);
|
if (with_mode) {
|
||||||
lua_call(L, 2, 2);
|
lua_pushvalue(L, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
lua_call(L, with_mode ? 2 : 1, 2);
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user