Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: concurrency crash in closeAllShopWindows caused by use-after-free #3211

Merged

Conversation

dudantas
Copy link
Member

@dudantas dudantas commented Jan 4, 2025

Description

This PR fixes a concurrency crash in the closeAllShopWindows method. The issue occurred when the shopPlayers map was cleared while being iterated over, leading to a use-after-free scenario. The solution removes the use of references when iterating over shopPlayers keys, ensuring that the keys are copied instead of directly referencing the map. This change prevents crashes and improves stability in concurrent environments.


Behaviour

Actual

  • Iterating over shopPlayers with references caused a crash in some scenarios because the map was cleared during the iteration, leading to use-after-free memory access.

Expected

  • Iterating over shopPlayers no longer results in crashes because the keys are copied, ensuring safe iteration even if the map is modified during the process.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested

  • Simulated scenarios where shopPlayers is cleared while being iterated to validate the fix.
  • Verified the safe execution of closeAllShopWindows under concurrent conditions without crashes.
  • Confirmed that removing references prevents memory access issues.

Checklist

  • My code follows the style guidelines of this project.
  • I have performed a self-review of my own code.
  • I checked the PR checks reports.
  • I have commented my code, particularly in hard-to-understand areas.
  • My changes generate no new warnings.
  • I have added tests that prove my fix is effective or that my feature works.

Fixed a concurrency crash in the `closeAllShopWindows` method. The issue occurred when the `shopPlayers` map was cleared while being iterated over, leading to a use-after-free scenario.

This fix ensures safe access by retrieving the player object before performing any operations and checking for its validity. This prevents memory access errors and improves the stability of the system in concurrent scenarios.
@majestyotbr majestyotbr merged commit 2ca896e into main Jan 5, 2025
21 of 24 checks passed
@majestyotbr majestyotbr deleted the dudantas/fix-crash-related-to-npc-close-shop-window branch January 5, 2025 00:00
Copy link

sonarqubecloud bot commented Jan 5, 2025

vllworldbuilding pushed a commit to vllworldbuilding/canary that referenced this pull request Jan 10, 2025
opentibiabr#3211)

This fixes a concurrency crash in the `closeAllShopWindows` method.
The issue occurred when the `shopPlayers` map was cleared while being iterated over, leading to a use-after-free scenario. The solution removes the use of references when iterating over `shopPlayers` keys, ensuring that the keys are copied instead of directly referencing the map. This change prevents crashes and improves stability in concurrent environments.
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.

3 participants