aboutsummaryrefslogtreecommitdiff
path: root/src/script/common/c_internal.cpp
diff options
context:
space:
mode:
authorElias Fleckenstein <eliasfleckenstein@web.de>2022-05-17 22:12:00 +0200
committerElias Fleckenstein <eliasfleckenstein@web.de>2022-05-17 22:12:00 +0200
commit21df26984da91143c15587f5a03c98d68c3adc4e (patch)
treeaaa707a628ad331f67890023dffe1b4f60dd01d3 /src/script/common/c_internal.cpp
parentb09fc5de5cdb021f43ad32b7e3f50dc75c0bc622 (diff)
parenteabf05758e3ba5f6f4bb1b8d1d1f02179b84e410 (diff)
downloaddragonfireclient-21df26984da91143c15587f5a03c98d68c3adc4e.tar.xz
Merge branch 'master' of https://github.com/minetest/minetest
Diffstat (limited to 'src/script/common/c_internal.cpp')
-rw-r--r--src/script/common/c_internal.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/script/common/c_internal.cpp b/src/script/common/c_internal.cpp
index df82dba14..ddd2d184c 100644
--- a/src/script/common/c_internal.cpp
+++ b/src/script/common/c_internal.cpp
@@ -166,3 +166,17 @@ void log_deprecated(lua_State *L, std::string message, int stack_depth)
infostream << script_get_backtrace(L) << std::endl;
}
+void call_string_dump(lua_State *L, int idx)
+{
+ // Retrieve string.dump from insecure env to avoid it being tampered with
+ lua_rawgeti(L, LUA_REGISTRYINDEX, CUSTOM_RIDX_GLOBALS_BACKUP);
+ if (!lua_isnil(L, -1))
+ lua_getfield(L, -1, "string");
+ else
+ lua_getglobal(L, "string");
+ lua_getfield(L, -1, "dump");
+ lua_remove(L, -2); // remove _G
+ lua_remove(L, -2); // remove 'string' table
+ lua_pushvalue(L, idx);
+ lua_call(L, 1, 1);
+}