Skip to content

Null-check plugin-supplied pointers in v1 Scripts API#149

Open
JustinMDotNet wants to merge 1 commit into
wopss:masterfrom
JustinMDotNet:fix/v1-scripts-null-checks
Open

Null-check plugin-supplied pointers in v1 Scripts API#149
JustinMDotNet wants to merge 1 commit into
wopss:masterfrom
JustinMDotNet:fix/v1-scripts-null-checks

Conversation

@JustinMDotNet

Copy link
Copy Markdown

Closes #137.

What this changes

Three v1 script-API entry points in src/dll/v1/Funcs.cpp now reject nullptr and log a warning before forwarding the pointer downstream:

  • v1::Scripts::Add(handle, aPath) — checks aPath
  • v1::Scripts::RegisterNeverRefType(aType) — checks aType
  • v1::Scripts::RegisterMixedRefType(aType) — checks aType

The shape mirrors the existing pattern in v1/Logger.cpp:11-31 so 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. aPath ends up in std::filesystem::path(aPath) (ScriptCompilationSystem.cpp:104) and spdlog::trace(L"...", aPath) (:103); both are UB on nullptr. The two Register*Type entry points pass into std::string(aType) (the std::string by-value parameter at ScriptCompilationSystem.cpp:81, 91), which is also UB on nullptr.

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.

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

v1 Scripts API does not null-check plugin-supplied path/type pointers

2 participants