Prevented longjmp into an uninitialised buffer during plugin faults by tracking when the hook jump buffer is actually primed; a missing/invalid buffer now skips the jump and falls back to crash reporting

This commit is contained in:
Rtur2003 2025-12-07 19:07:07 +03:00
parent 76ac655c9e
commit e8a9615204
2 changed files with 6 additions and 0 deletions

View file

@ -50,6 +50,7 @@ void CHookSystemManager::emit(std::vector<SCallbackFNPtr>* const callbacks, SCal
continue; continue;
try { try {
m_hookFaultJumpBufReady = true;
if (!setjmp(m_hookFaultJumpBuf)) { if (!setjmp(m_hookFaultJumpBuf)) {
if (SP<HOOK_CALLBACK_FN> fn = cb.fn.lock()) if (SP<HOOK_CALLBACK_FN> fn = cb.fn.lock())
(*fn)(fn.get(), info, data); (*fn)(fn.get(), info, data);
@ -63,7 +64,11 @@ void CHookSystemManager::emit(std::vector<SCallbackFNPtr>* const callbacks, SCal
// TODO: this works only once...? // TODO: this works only once...?
faultyHandles.push_back(cb.handle); faultyHandles.push_back(cb.handle);
Debug::log(ERR, "[hookSystem] Hook from plugin {:x} caused a SIGSEGV, queueing for unloading.", rc<uintptr_t>(cb.handle)); Debug::log(ERR, "[hookSystem] Hook from plugin {:x} caused a SIGSEGV, queueing for unloading.", rc<uintptr_t>(cb.handle));
} catch (...) {
faultyHandles.push_back(cb.handle);
Debug::log(ERR, "[hookSystem] Hook from plugin {:x} caused an unknown fault, queueing for unloading.", rc<uintptr_t>(cb.handle));
} }
m_hookFaultJumpBufReady = false;
} }
if (needsDeadCleanup) if (needsDeadCleanup)

View file

@ -51,6 +51,7 @@ class CHookSystemManager {
std::vector<SCallbackFNPtr>* getVecForEvent(const std::string& event); std::vector<SCallbackFNPtr>* getVecForEvent(const std::string& event);
bool m_currentEventPlugin = false; bool m_currentEventPlugin = false;
bool m_hookFaultJumpBufReady = false;
jmp_buf m_hookFaultJumpBuf; jmp_buf m_hookFaultJumpBuf;
private: private: