Null-check plugin-supplied pointers in v1 Scripts API#149
Open
JustinMDotNet wants to merge 1 commit into
Open
Conversation
The three Scripts entry points in v1::Funcs forwarded their raw pointer arguments straight into std::filesystem::path / std::string constructors downstream, both of which are UB on nullptr. A plugin that called Scripts::Add(handle, nullptr) or RegisterNeverRefType(nullptr) / RegisterMixedRefType(nullptr) would crash the game process. Mirror the existing pattern in v1/Logger.cpp: reject nullptr at the boundary, log a warning, and return false without forwarding the call. Fixes wopss#137 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 #137.
What this changes
Three v1 script-API entry points in
src/dll/v1/Funcs.cppnow rejectnullptrand log a warning before forwarding the pointer downstream:v1::Scripts::Add(handle, aPath)— checksaPathv1::Scripts::RegisterNeverRefType(aType)— checksaTypev1::Scripts::RegisterMixedRefType(aType)— checksaTypeThe shape mirrors the existing pattern in
v1/Logger.cpp:11-31so the v1 surface is consistent: null in → warn + return false, no work done.Why
Without these checks, a plugin that called e.g.
sdk->scripts->Add(handle, nullptr)would crash the game process.aPathends up instd::filesystem::path(aPath)(ScriptCompilationSystem.cpp:104) andspdlog::trace(L"...", aPath)(:103); both are UB onnullptr. The twoRegister*Typeentry points pass intostd::string(aType)(thestd::stringby-value parameter atScriptCompilationSystem.cpp:81, 91), which is also UB onnullptr.It does not need to be a malicious plugin to hit this — any plugin that derives the path from a config file and forgets to handle "missing key" reproduces it on the first run.
What I tested
Local rebuild. Behavior change is limited to the null-input path, which previously crashed; non-null inputs behave identically.