From 4edcd52b074c050890115d597937053949642ab7 Mon Sep 17 00:00:00 2001 From: Benjamin Wrensch Date: Sun, 18 Aug 2024 19:08:35 +0200 Subject: [PATCH] [add] safer handling of executing scripts via api --- iolite_plugins/lua_plugin/lua_plugin.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/iolite_plugins/lua_plugin/lua_plugin.cpp b/iolite_plugins/lua_plugin/lua_plugin.cpp index 62dd592..551067d 100644 --- a/iolite_plugins/lua_plugin/lua_plugin.cpp +++ b/iolite_plugins/lua_plugin/lua_plugin.cpp @@ -925,9 +925,12 @@ IO_API_EXPORT int IO_API_CALL load_plugin(void* api_manager) // Register the interfaces we provide { io_plugin_lua.execute_script = [](const char* script) { - sol::state s; - script_init_state(s); - s.script(script); + sol::state state; + script_init_state(state); + auto s = state.load(script); + + if (s.valid()) + SOL_VALIDATE_RESULT(s(), "Call to 'execute_script'"); }; io_api_manager->register_api(IO_PLUGIN_LUA_API_NAME, &io_plugin_lua);