Skip to content

Commit

Permalink
Fix Lua panic when error() message is not a string
Browse files Browse the repository at this point in the history
  • Loading branch information
p-ouellette authored and sfan5 committed Jun 7, 2020
1 parent fe1f72a commit 09f9e46
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/script/cpp_api/s_base.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 09f9e46

Please sign in to comment.