From c3254c88cae6830715f608c7e0e8a35e28479e15 Mon Sep 17 00:00:00 2001 From: VladimirMangos Date: Tue, 7 Dec 2010 12:26:20 +0300 Subject: [PATCH] [10833] Avoid use unsafe remove auras in aura apply code. Specailly example Aura::HandleModCharm code where old code call RemoveSpellsCausingAura or (a) dead and not called, or (b) will remove aura self at call. * Added safe for aura holder context version of RemoveSpellsCausingAura * Cleanup old simple RemoveSpellsCausingAura code also. --- src/game/SpellAuras.cpp | 12 +++++------- src/game/Unit.cpp | 27 ++++++++++++++++----------- src/game/Unit.h | 1 + src/shared/revision_nr.h | 2 +- 4 files changed, 23 insertions(+), 19 deletions(-) diff --git a/src/game/SpellAuras.cpp b/src/game/SpellAuras.cpp index b23871c1d..38b58236d 100644 --- a/src/game/SpellAuras.cpp +++ b/src/game/SpellAuras.cpp @@ -2930,7 +2930,7 @@ void Aura::HandleAuraModShapeshift(bool apply, bool Real) case FORM_MOONKIN: { // remove movement affects - target->RemoveSpellsCausingAura(SPELL_AURA_MOD_ROOT); + target->RemoveSpellsCausingAura(SPELL_AURA_MOD_ROOT, GetHolder()); Unit::AuraList const& slowingAuras = target->GetAurasByType(SPELL_AURA_MOD_DECREASE_SPEED); for (Unit::AuraList::const_iterator iter = slowingAuras.begin(); iter != slowingAuras.end();) { @@ -3227,7 +3227,7 @@ void Aura::HandleAuraTransform(bool apply, bool Real) //dismount polymorphed target (after patch 2.4.2) if (target->IsMounted()) - target->RemoveSpellsCausingAura(SPELL_AURA_MOUNTED); + target->RemoveSpellsCausingAura(SPELL_AURA_MOUNTED, GetHolder()); } } else @@ -3639,11 +3639,9 @@ void Aura::HandleModCharm(bool apply, bool Real) if( apply ) { - if (!target->GetCharmerGuid().IsEmpty()) - { - target->RemoveSpellsCausingAura(SPELL_AURA_MOD_CHARM); - target->RemoveSpellsCausingAura(SPELL_AURA_MOD_POSSESS); - } + // is it really need after spell check checks? + target->RemoveSpellsCausingAura(SPELL_AURA_MOD_CHARM, GetHolder()); + target->RemoveSpellsCausingAura(SPELL_AURA_MOD_POSSESS, GetHolder()); target->SetCharmerGuid(GetCasterGuid()); target->setFaction(caster->getFaction()); diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp index ab80d1ce7..76b10af85 100644 --- a/src/game/Unit.cpp +++ b/src/game/Unit.cpp @@ -456,21 +456,26 @@ bool Unit::canReachWithAttack(Unit *pVictim) const void Unit::RemoveSpellsCausingAura(AuraType auraType) { - if (auraType >= TOTAL_AURAS) return; - AuraList::const_iterator iter, next; - for (iter = m_modAuras[auraType].begin(); iter != m_modAuras[auraType].end(); iter = next) + for (AuraList::const_iterator iter = m_modAuras[auraType].begin(); iter != m_modAuras[auraType].end();) { - next = iter; - ++next; + RemoveAurasDueToSpell((*iter)->GetId()); + iter = m_modAuras[auraType].begin(); + } +} - if (*iter) +void Unit::RemoveSpellsCausingAura(AuraType auraType, SpellAuraHolder* except) +{ + for (AuraList::const_iterator iter = m_modAuras[auraType].begin(); iter != m_modAuras[auraType].end();) + { + // skip `except` aura + if ((*iter)->GetHolder() == except) { - RemoveAurasDueToSpell((*iter)->GetId()); - if (!m_modAuras[auraType].empty()) - next = m_modAuras[auraType].begin(); - else - return; + ++iter; + continue; } + + RemoveAurasDueToSpell((*iter)->GetId(), except); + iter = m_modAuras[auraType].begin(); } } diff --git a/src/game/Unit.h b/src/game/Unit.h index dfea27e0d..f337a8443 100644 --- a/src/game/Unit.h +++ b/src/game/Unit.h @@ -1602,6 +1602,7 @@ class MANGOS_DLL_SPEC Unit : public WorldObject void RemoveNotOwnSingleTargetAuras(uint32 newPhase = 0x0); void RemoveAurasAtMechanicImmunity(uint32 mechMask, uint32 exceptSpellId, bool non_positive = false); void RemoveSpellsCausingAura(AuraType auraType); + void RemoveSpellsCausingAura(AuraType auraType, SpellAuraHolder* except); void RemoveRankAurasDueToSpell(uint32 spellId); bool RemoveNoStackAurasDueToAuraHolder(SpellAuraHolder *holder); void RemoveAurasWithInterruptFlags(uint32 flags); diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index f88f14bb5..47fedb4d9 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "10832" + #define REVISION_NR "10833" #endif // __REVISION_NR_H__