Skip to content

Commit 9e10f9f

Browse files
committedNov 24, 2016
Fix secure io.open without mode
1 parent 0d1c959 commit 9e10f9f

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed
 

‎src/script/cpp_api/s_security.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -525,14 +525,19 @@ int ScriptApiSecurity::sl_g_require(lua_State *L)
525525

526526
int ScriptApiSecurity::sl_io_open(lua_State *L)
527527
{
528+
bool with_mode = lua_gettop(L) > 1;
529+
528530
luaL_checktype(L, 1, LUA_TSTRING);
529531
const char *path = lua_tostring(L, 1);
530532
CHECK_SECURE_PATH(L, path);
531533

532534
push_original(L, "io", "open");
533535
lua_pushvalue(L, 1);
534-
lua_pushvalue(L, 2);
535-
lua_call(L, 2, 2);
536+
if (with_mode) {
537+
lua_pushvalue(L, 2);
538+
}
539+
540+
lua_call(L, with_mode ? 2 : 1, 2);
536541
return 2;
537542
}
538543

0 commit comments

Comments
 (0)
Please sign in to comment.