Skip to content

fix(Core/OutdoorPvP): Fix use-after-free in DelCapturePoint#25229

Open
blinkysc wants to merge 1 commit intoazerothcore:masterfrom
blinkysc:fix/outdoor-pvp-use-after-free
Open

fix(Core/OutdoorPvP): Fix use-after-free in DelCapturePoint#25229
blinkysc wants to merge 1 commit intoazerothcore:masterfrom
blinkysc:fix/outdoor-pvp-use-after-free

Conversation

@blinkysc
Copy link
Copy Markdown
Contributor

Changes Proposed:

Minor shutdown-only use-after-free: OPvPCapturePoint::DelCapturePoint() called DeleteGOData() before _capturePoint->Delete(), freeing the GameObjectData while Delete()SetLootState()GetScriptId() still accesses it.

Reorders to match DelObject() directly above, which already has the correct order (delete GO first, then erase data).

Only triggers during server shutdown via OutdoorPvPMgr::Die() — no gameplay impact.

This PR proposes changes to:

  • Core (units, players, creatures, game systems).
  • Scripts (bosses, spell scripts, creature scripts).
  • Database (SAI, creatures, etc).

AI-assisted Pull Requests

Important

While the use of AI tools when preparing pull requests is not prohibited, contributors must clearly disclose when such tools have been used and specify the model involved.

Contributors are also expected to fully understand the changes they are submitting and must be able to explain and justify those changes when requested by maintainers.

  • AI tools (e.g. ChatGPT, Claude, or similar) were used entirely or partially in preparing this pull request. Claude Code with azerothMCP was used to analyze the ASAN trace and identify the fix.

Issues Addressed:

  • Found via AddressSanitizer during shutdown (OutdoorPvPGH)

SOURCE:

The changes have been validated through:

  • Live research (checked on live servers, e.g Classic WotLK, Retail, etc.)
  • Sniffs (remember to share them with the open source community!)
  • Video evidence, knowledge databases or other public sources (e.g forums, Wowhead, etc.)
  • The changes promoted by this pull request come partially or entirely from another project (cherry-pick).

Tests Performed:

This PR has been:

  • Tested in-game by the author.
  • Tested in-game by other community members/someone else other than the author/has been live on production servers.
  • This pull request requires further testing and may have edge cases to be tested.

How to Test the Changes:

  • This pull request can be tested by following the reproduction steps provided in the linked issue
  • This pull request requires further testing. Provide steps to test your changes. If it requires any specific setup e.g multiple players please specify it as well.
  1. Build with AddressSanitizer (-DCMAKE_CXX_FLAGS="-fsanitize=address")
  2. Start worldserver, then shut it down cleanly
  3. Verify no ASAN heap-use-after-free in GameObject::GetScriptId during OutdoorPvPMgr::Die()

Known Issues and TODO List:

  • N/A

How to Test AzerothCore PRs

When a PR is ready to be tested, it will be marked as [WAITING TO BE TESTED].

You can help by testing PRs and writing your feedback here on the PR's page on GitHub. Follow the instructions here:

http://www.azerothcore.org/wiki/How-to-test-a-PR

REMEMBER: when testing a PR that changes something generic (i.e. a part of code that handles more than one specific thing), the tester should not only check that the PR does its job (e.g. fixing spell XXX) but especially check that the PR does not cause any regression (i.e. introducing new bugs).

For example: if a PR fixes spell X by changing a part of code that handles spells X, Y, and Z, we should not only test X, but we should test Y and Z as well.

…urePoint

DeleteGOData was called before _capturePoint->Delete(), freeing the
GameObjectData while Delete() still accesses it via GetScriptId().
Reorder to match DelObject() which correctly deletes the GO first.
@sudlud sudlud requested a review from Copilot March 25, 2026 16:50
@github-actions github-actions bot added CORE Related to the core file-cpp Used to trigger the matrix build labels Mar 25, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a shutdown-time use-after-free in OPvPCapturePoint::DelCapturePoint() by reordering deletion of GameObjectData to occur after the capture point GameObject is deleted, matching the (already-correct) ordering used in DelObject().

Changes:

  • Reordered DeleteGOData() to run after _capturePoint->Delete()
  • Keeps spawn id reset (m_capturePointSpawnId = 0) aligned with the data deletion

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

if (_capturePoint)
{
_capturePoint->SetRespawnTime(0); // not save respawn time
_capturePoint->Delete();
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_capturePoint remains non-null after calling _capturePoint->Delete(). If Delete() frees the object (or makes the pointer invalid), leaving the member pointer set can enable later use-after-free via any subsequent _capturePoint checks. Consider clearing the member immediately after deletion (e.g., set _capturePoint = nullptr; after Delete()) to make the object lifecycle explicit and prevent accidental reuse.

Suggested change
_capturePoint->Delete();
_capturePoint->Delete();
_capturePoint = nullptr;

Copilot uses AI. Check for mistakes.
Comment on lines +224 to +225
sObjectMgr->DeleteGOData(m_capturePointSpawnId);
m_capturePointSpawnId = 0;
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DeleteGOData(m_capturePointSpawnId) is called unconditionally. If m_capturePointSpawnId can legitimately be 0 (it’s set to 0 here and likely used as a sentinel), consider guarding the delete with if (m_capturePointSpawnId) to avoid relying on implicit behavior of DeleteGOData(0) and to make intent clearer.

Suggested change
sObjectMgr->DeleteGOData(m_capturePointSpawnId);
m_capturePointSpawnId = 0;
if (m_capturePointSpawnId)
{
sObjectMgr->DeleteGOData(m_capturePointSpawnId);
m_capturePointSpawnId = 0;
}

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CORE Related to the core file-cpp Used to trigger the matrix build Ready to be Reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants