diff options
author | r4dish <ovitnez@gmail.com> | 2024-06-08 20:46:07 +0200 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2024-06-08 21:17:35 +0200 |
commit | d9460428c6639ea8dc3f66e0e39cd37cf62a1252 (patch) | |
tree | 5e5298528aa1eb0370b9a5babf07eab75748787e | |
parent | 70d6121ef47573555218ad072c425cfb74c29558 (diff) |
Core/Spells: Fix sobering spells and possible uint8 overflow/underflow in SPELL_EFFECT_INEBRIATE handler.
-rw-r--r-- | src/server/game/Spells/SpellEffects.cpp | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/src/server/game/Spells/SpellEffects.cpp b/src/server/game/Spells/SpellEffects.cpp index 70eafbcb172..51c729a37a2 100644 --- a/src/server/game/Spells/SpellEffects.cpp +++ b/src/server/game/Spells/SpellEffects.cpp @@ -3896,17 +3896,25 @@ void Spell::EffectInebriate() Player* player = unitTarget->ToPlayer(); uint8 currentDrunk = player->GetDrunkValue(); - uint8 drunkMod = damage; - if (currentDrunk + drunkMod > 100) - { + int32 drunkMod = damage; + + if (drunkMod == 0) + return; + + // drunkMod may contain values that are guaranteed to cause uint8 overflow/underflow (examples: 29690, 46874) + // In addition, we would not want currentDrunk to become more than 100. + // So before adding the values, let's check that everything is fine. + if (drunkMod > static_cast<int32>(100 - currentDrunk)) currentDrunk = 100; - if (rand_chance() < 25.0f) - player->CastSpell(player, 67468, false); // Drunken Vomit - } + else if (drunkMod < static_cast<int32>(0 - currentDrunk)) + currentDrunk = 0; else - currentDrunk += drunkMod; + currentDrunk += drunkMod; // Due to previous checks we can be sure that currentDrunk will not go beyond [0-100] range. player->SetDrunkValue(currentDrunk, m_CastItem ? m_CastItem->GetEntry() : 0); + + if (currentDrunk == 100 && roll_chance_i(25)) + player->CastSpell(player, 67468, false); // Drunken Vomit } void Spell::EffectFeedPet() |