Skip to content

fix CTD when LuaSEXP evaluates a subsystem on an absent ship#7496

Merged
Goober5000 merged 1 commit into
scp-fs2open:masterfrom
Goober5000:fix/7206
Jun 4, 2026
Merged

fix CTD when LuaSEXP evaluates a subsystem on an absent ship#7496
Goober5000 merged 1 commit into
scp-fs2open:masterfrom
Goober5000:fix/7206

Conversation

@Goober5000

Copy link
Copy Markdown
Contributor

The OPF_SUBSYSTEM argument-conversion path in LuaSEXP only verified has_shipp() before calling ship_entry->objp(). A ship registry entry retains its shipnum after the ship is destroyed or departed, but its objnum is reset to -1, so objp() either asserts (debug) or dereferences Objects[-1] (release) when the entry is looked up by Lua scripting during, for example, an OnMissionAboutToEnd hook.

Tighten the check to has_objp() so absent ships short-circuit to an empty handle, and correct the early-return type from l_Ship to l_Subsystem. Apply the matching type correction to OPF_DOCKER_POINT, which has the same return-type mismatch but no CTD because it never dereferences objp().

Fixes #7206.

The OPF_SUBSYSTEM argument-conversion path in LuaSEXP only verified
has_shipp() before calling ship_entry->objp().  A ship registry entry
retains its shipnum after the ship is destroyed or departed, but its
objnum is reset to -1, so objp() either asserts (debug) or dereferences
Objects[-1] (release) when the entry is looked up by Lua scripting
during, for example, an OnMissionAboutToEnd hook.

Tighten the check to has_objp() so absent ships short-circuit to an
empty handle, and correct the early-return type from l_Ship to
l_Subsystem.  Apply the matching type correction to OPF_DOCKER_POINT,
which has the same return-type mismatch but no CTD because it never
dereferences objp().

Fixes scp-fs2open#7206.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@Goober5000 Goober5000 added fix A fix for bugs, not-a-bugs, and/or regressions. scripting A feature or issue related to LUA scripting labels Jun 3, 2026
@Goober5000 Goober5000 requested a review from BMagnu June 3, 2026 20:42
@Goober5000 Goober5000 merged commit 343bc17 into scp-fs2open:master Jun 4, 2026
20 checks passed
@Goober5000 Goober5000 deleted the fix/7206 branch June 4, 2026 01:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix A fix for bugs, not-a-bugs, and/or regressions. scripting A feature or issue related to LUA scripting

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Specific scripting combinations can access invalid ships

3 participants