Author: silene
Date: Sun Mar 22 19:59:38 2009
New Revision: 34044
URL: http://svn.gna.org/viewcvs/wesnoth?rev=34044&view=rev
Log:
Removed arbitrary access to Lua files.
Modified:
trunk/src/scripting/lua.cpp
Modified: trunk/src/scripting/lua.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/scripting/lua.cpp?rev=34044&r1=34043&r2=34044&view=diff
==============================================================================
--- trunk/src/scripting/lua.cpp (original)
+++ trunk/src/scripting/lua.cpp Sun Mar 22 19:59:38 2009
@@ -17,6 +17,7 @@
#include <cstring>
#include <iostream>
+#include "filesystem.hpp"
#include "foreach.hpp"
#include "gamestatus.hpp"
#include "scripting/lua.hpp"
@@ -96,7 +97,7 @@
* Converts a Lua table to a config object.
* The source table should be at the top of the stack on entry. It is
* still at the top on exit.
- * @a tstring_meta absolute stack position of t_string's metatable, or 0 if
none.
+ * @param tstring_meta absolute stack position of t_string's metatable, or 0
if none.
* @return false if some attributes had not the proper type.
* @note If the table has holes in the integer keys or floating-point keys,
* some keys will be ignored and the error will go undetected.
@@ -462,6 +463,33 @@
return 0;
}
+/**
+ * Loads and executes a Lua file.
+ * - Arg 1: string containing the file name.
+ * - Ret *: values returned by executing the file body.
+ */
+static int lua_dofile(lua_State *L)
+{
+ char const *m = luaL_checkstring(L, 1);
+ if (false) {
+ error_call_destructors_1:
+ return luaL_argerror(L, 1, "file not found");
+ error_call_destructors_2:
+ return lua_error(L);
+ continue_call_destructor:
+ lua_call(L, 0, 1);
+ return 1;
+ }
+ std::string p = get_wml_location(m);
+ if (p.empty())
+ goto error_call_destructors_1;
+
+ if (luaL_loadfile(L, p.c_str()))
+ goto error_call_destructors_2;
+
+ goto continue_call_destructor;
+}
+
static int lua_message(lua_State *L)
{
char const *m = luaL_checkstring(L, 1);
@@ -497,6 +525,7 @@
{ "get_units", &lua_get_units },
{ "get_variable", &lua_get_variable },
{ "message", &lua_message },
+ { "dofile", &lua_dofile },
{ "set_variable", &lua_set_variable },
{ "textdomain", &lua_textdomain },
{ NULL, NULL }
@@ -532,6 +561,12 @@
lua_setfield(L, -2, "__metatable");
lua_settable(L, LUA_REGISTRYINDEX);
+ // Delete dofile and loadfile.
+ lua_pushnil(L);
+ lua_setglobal(L, "dofile");
+ lua_pushnil(L);
+ lua_setglobal(L, "loadfile");
+
// Push the error handler, then close debug.
lua_settop(L, 0);
lua_getglobal(L, "debug");
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits