Fix #5173: prevent server crash on invalid elementData argument - #5176
Fix #5173: prevent server crash on invalid elementData argument#5176MohabCodeX wants to merge 6 commits into
Conversation
|
This doesn't address the root cause of the problem - it's just a workaround, and an incomplete one at that. |
If I add a safe helper method inside int ThrowError()
{
return luaL_error(m_luaVM, "%s", GetFullErrorMessage().c_str());
}And replace the raw luaL_error argument error calls with argStream.ThrowError(), would that be the right direction to fix this systemically? |
|
The key point isn't where |
Implement systemic exception-safe error handling by throwing LuaFunctionError C++ exception instead of executing raw luaL_error longjmp directly inside CScriptArgReader. This ensures proper C++ RAII stack unwinding so local object destructors execute safely before luaL_error is caught and dispatched at the outer function boundary.
095db38 to
4c444a8
Compare
Makes sense, thanks 🤍 |
|
Inside |
|
I see what you mean, but since we're throwing a standard C++ exception here instead of calling That said, if you'd still prefer avoiding that temporary |
|
FunctionParser still calls luaL_error, so the root cause isn't fully addressed. It looks like we're merely postponing the longjmp. |
|
Calling To address this systemically, I've updated all 86 |
…Error() Replaces all 86 unsafe luaL_error(luaVM, argStream.GetFullErrorMessage()) calls across 10 luadefs files with argStream.ThrowError(). When argStream has errors, calling luaL_error directly bypasses destructors for active C++ objects on the stack via longjmp. Throwing LuaFunctionError allows exception unwinding to cleanly destroy all local C++ stack objects before luaL_error is dispatched at the CLuaFunctionParser boundary.
2083b98 to
ede6972
Compare
Summary
Refactor
CScriptArgReadererror handling to useLuaFunctionErrorexceptions instead of callingluaL_errordirectly.Motivation
Fixes #5173.
Calling
luaL_errorwhile C++ objects are still on the stack can skip their destructors because Lua useslongjmpfor error handling. This can cause memory leaks, heap corruption, or crashes.The idea here is to let C++ handle the stack unwinding first, then report the error to Lua.
In short:
CScriptArgReader::ThrowError()throwsLuaFunctionError.CLuaFunctionParsercatches the exception and callsluaL_erroronce the stack is clean.Test Plan
arg_reader_suite.zip