summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Ouellette <oue.paul18@gmail.com>2020-06-06 14:52:26 -0400
committersfan5 <sfan5@live.de>2020-06-07 18:14:40 +0200
commit09f9e465e760cb8fd791222405a9e5e68a676ba0 (patch)
tree252a633df35ccccc926aecda92040c8cd616544a /src
parentfe1f72ab0ac8bcc233c91eb5b2d71bd2d2574cf8 (diff)
downloadminetest-09f9e465e760cb8fd791222405a9e5e68a676ba0.tar.gz
minetest-09f9e465e760cb8fd791222405a9e5e68a676ba0.tar.bz2
minetest-09f9e465e760cb8fd791222405a9e5e68a676ba0.zip
Fix Lua panic when error() message is not a string
Diffstat (limited to 'src')
-rw-r--r--src/script/cpp_api/s_base.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/script/cpp_api/s_base.cpp b/src/script/cpp_api/s_base.cpp
index df07206d7..f965975a3 100644
--- a/src/script/cpp_api/s_base.cpp
+++ b/src/script/cpp_api/s_base.cpp
@@ -187,7 +187,9 @@ void ScriptApiBase::loadScript(const std::string &script_path)
}
ok = ok && !lua_pcall(L, 0, 0, error_handler);
if (!ok) {
- std::string error_msg = readParam<std::string>(L, -1);
+ const char *error_msg = lua_tostring(L, -1);
+ if (!error_msg)
+ error_msg = "(error object is not a string)";
lua_pop(L, 2); // Pop error message and error handler
throw ModError("Failed to load and run script from " +
script_path + ":\n" + error_msg);
@@ -219,7 +221,9 @@ void ScriptApiBase::loadModFromMemory(const std::string &mod_name)
if (ok)
ok = !lua_pcall(L, 0, 0, error_handler);
if (!ok) {
- std::string error_msg = luaL_checkstring(L, -1);
+ const char *error_msg = lua_tostring(L, -1);
+ if (!error_msg)
+ error_msg = "(error object is not a string)";
lua_pop(L, 2); // Pop error message and error handler
throw ModError("Failed to load and run mod \"" +
mod_name + "\":\n" + error_msg);