Core/Misc: Fix out of bounds access on startup

Fix out of bound access on startup trying to access SpellEffects with ID greater than max allowed/known.
Reported by AddressSanitizer .
This commit is contained in:
jackpoz
2017-12-02 12:56:23 +01:00
committed by Aokromes
parent e2f62cb5bc
commit 081e7aa708

View File

@@ -2617,6 +2617,22 @@ void SpellMgr::LoadSpellInfoStore()
if (SpellEntry const* spellEntry = sSpellStore.LookupEntry(i))
mSpellInfoMap[i] = new SpellInfo(spellEntry, effectsBySpell[i].effects);
for (uint32 spellIndex = 0; spellIndex < GetSpellInfoStoreSize(); ++spellIndex)
{
if (!mSpellInfoMap[spellIndex])
continue;
for (uint32 effectIndex = 0; effectIndex < MAX_SPELL_EFFECTS; ++effectIndex)
{
if (mSpellInfoMap[spellIndex]->Effects[effectIndex].Effect >= TOTAL_SPELL_EFFECTS)
{
TC_LOG_ERROR("sql.sql", "Spell (Entry: %u) has `Effect` '%u' greater than max allowed value '%u', removing", spellIndex, mSpellInfoMap[spellIndex]->Effects[effectIndex].Effect, (TOTAL_SPELL_EFFECTS - 1));
mSpellInfoMap[spellIndex]->Effects[effectIndex].Effect = 0;
}
}
}
TC_LOG_INFO("server.loading", ">> Loaded SpellInfo store in %u ms", GetMSTimeDiffToNow(oldMSTime));
}