Guard item.original write in HookingSystem::Detach#145
Open
JustinMDotNet wants to merge 1 commit into
Open
Conversation
HookingSystem::Attach already treats aOriginal as optional and only
writes to it when it is non-null. The v1 entry point in Funcs.cpp
also lets plugins pass nullptr for the original-out pointer (only
aTarget and aDetour are required). HookingSystem::Detach, however,
unconditionally executed:
*item.original = nullptr;
after a successful detach, so any plugin that registered a hook
without asking for the original trampoline would crash the game
process the moment it removed that hook.
Mirror Attach's check by only writing through item.original when it
is non-null. Shutdown is not affected because it uses
QueueForDetach + m_hooks.clear() and never writes through
item.original.
Fixes wopss#136
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #136.
What this changes
HookingSystem::Detachnow guards the write toitem.originalwith a null check, the same wayAttachalready does:Why
HookingSystem::AttachtreatsaOriginalas optional (it only writes through it when it is non-null, seeHookingSystem.cpp:64), and the v1 entry point inFuncs.cpp:40-44only rejects nullaTargetandaDetour—aOriginalis allowed to be null. But the previousDetachdid*item.original = nullptr;unconditionally, so any plugin that legitimately registered a hook without asking for the original trampoline would crash the game process the first time it removed that hook.Reproducer:
HookingSystem::Shutdownis not affected because it usesQueueForDetach+m_hooks.clear()and never writes throughitem.original.What I tested
Local rebuild. Behavior change is limited to the
aOriginal == nullptrpath, which previously always crashed; for plugins that passed a non-nullaOriginalthe behavior is identical.Alternative considered
Rejecting
aOriginal == nullptrat the v1 boundary inFuncs.cpp::v1::Hooking::Attach. That is a contract change and breaks the symmetry withAttach's existing optional-out behavior, so I went with the guard. Happy to switch to the boundary check if you would prefer.