18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-27 23:57:09 +01:00
Commit Graph

1 Commits

Author SHA1 Message Date
jerrrrycho
acda6562cd fix(scripting): sandbox the scenery Lua scripts like the Lua screens
The scenery scripts (lua <file> in the .scn) ran in a state with all of
LuaJIT's libraries (io, os, ffi, debug, require, load*), loaded with
luaL_dofile from any path, '..' and absolute ones included, and their
errors in event handlers went through an unprotected lua_call.

- scripting/luasandbox.{h,cpp}: what the Lua states share: the safe
  library set (moved from lua_program::open_libraries), loading a text-only
  chunk (moved from load_chunk), reading a script from a folder through the
  screens' path check (regular file, at most 16 MB), running it under pcall,
  and a clock-only os table (time, clock, difftime, date with the C89
  conversions; MSVC's strftime ends the program on an unknown one).
- lua.cpp: the scenery state gets the safe set and the clock; interpret()
  takes the scenery folder and the file and logs a refused or failing script
  with its file name; event handlers run under pcall and are logged with the
  event name; the scriptapi functions check their string argument
  (luaL_checkstring) instead of making a std::string from NULL; a memcell
  table without str updates the text to "" instead of from NULL.
- luaprogram.cpp: calls the shared helpers, no change for the screens.
- eu07.ini lua.fulllibraries (default no) gives trusted sceneries all
  libraries back. Documented in script_screens_doc.md.
- tests/unit/test_lua_sandbox.cpp: 8 cases for the shared sandbox.
2026-11-13 15:23:01 +01:00