otland / forgottenserver

A free and open-source MMORPG server emulator written in C++
https://otland.net
GNU General Public License v2.0
1.58k stars 1.05k forks source link

Fix use-after-free in creature conditions #4726

Closed diath closed 4 months ago

diath commented 4 months ago

The Creature class destructor loops over the conditions member variable and calls condition->endCondition then deletes the condition object, however, ConditionInvisible::endCondition calls Creature::isInvisible, which subsequently loops over the conditions (which are not erased when being deleted in the destructor), calling condition->getType on an already deleted memory, resulting in UAF. This fixes the issue by first ending all conditions, then deleting them separately (as erasing the elements one-by-one in the Creature destructor does not make much sense).