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

SAGA: Fix use-after-free on handling actor action #5054

Merged

Conversation

PushmePullyu
Copy link
Contributor

@PushmePullyu PushmePullyu commented May 28, 2023

On switching scenes:
Reset _actor->_lastZone in Actor::updateActorsScene().

Actors can store a pointer to a HitZone in _lastZone (see Actor::handleActions()).

The HitZone pointed to is held by ObjectMap vm->_scene->_objectMap in array _hitZoneList.

When changing scenes the array elements are cleared via ObjectMap::clear() and _lastZone can become stale since only some code paths reset it (e.g. Actor::takeExit()).

The stale pointer is then passed to Actor::stepZoneAction() from Actor::handleActions() and dereferenced.

Fixes #13661

Thanks to @dwatteau for building and testing on OSX PPC.

On switching scenes:
Reset _actor->_lastZone in Actor::updateActorsScene().

Actors can store a pointer to a HitZone in _lastZone
(see Actor::handleActions()).

The HitZone pointed to is held by ObjectMap vm->_scene->_objectMap
in array _hitZoneList.

When changing scenes the array elements are cleared via
ObjectMap::clear() and _lastZone can become stale since
only some code paths reset it (e.g. Actor::takeExit()).

The stale pointer is then passed to Actor::stepZoneAction()
from Actor::handleActions() and dereferenced.

Fixes #13661
@bluegr
Copy link
Member

bluegr commented May 28, 2023

Very nice work! Thanks for investigating this

@bluegr bluegr merged commit bad85b3 into scummvm:master May 28, 2023
8 checks passed
@PushmePullyu PushmePullyu deleted the fix-saga-use-after-free-in-stepzoneaction branch June 12, 2023 21:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants