[Crash] Add Checks for out of bounds & dereferencing nullptrs (#3151)

* [Crash] Add Checks for out of bounds/nullptr dereferences

* formatting

* formatting

* formatting

* Update bot.cpp

---------

Co-authored-by: Alex King <89047260+Kinglykrab@users.noreply.github.com>
This commit is contained in:
Aeadoin 2023-03-27 21:43:46 -04:00 committed by GitHub
parent 87cb74b851
commit 8bdcf7cb94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 56 additions and 44 deletions

View File

@ -2735,18 +2735,15 @@ void Bot::CalcMeleeDistances(const Mob* tar, const EQ::ItemInstance* const& p_it
bool Bot::IsValidTarget(Client* bot_owner, Client* leash_owner, float lo_distance, float leash_distance, bool bo_alt_combat, Mob* tar, float tar_distance) { bool Bot::IsValidTarget(Client* bot_owner, Client* leash_owner, float lo_distance, float leash_distance, bool bo_alt_combat, Mob* tar, float tar_distance) {
if (HOLDING || if (!tar || !bot_owner || !leash_owner) {
!tar->IsNPC() || return false;
tar->IsMezzed() || }
lo_distance > leash_distance ||
tar_distance > leash_distance || bool valid_target_state = HOLDING || !tar->IsNPC() || tar->IsMezzed() || lo_distance > leash_distance || tar_distance > leash_distance;
(!GetAttackingFlag() && !CheckLosFN(tar) && !leash_owner->CheckLosFN(tar)) || // This is suppose to keep bots from attacking things behind walls bool valid_target = !GetAttackingFlag() && !CheckLosFN(tar) && !leash_owner->CheckLosFN(tar);
!IsAttackAllowed(tar) || bool valid_bo_target = !GetAttackingFlag() && NOT_PULLING_BOT && !leash_owner->AutoAttackEnabled() && !tar->GetHateAmount(this) && !tar->GetHateAmount(leash_owner);
(bo_alt_combat &&
(!GetAttackingFlag() && NOT_PULLING_BOT && !leash_owner->AutoAttackEnabled() && !tar->GetHateAmount(this) && !tar->GetHateAmount(leash_owner)) if (valid_target_state || valid_target || !IsAttackAllowed(tar) || (bo_alt_combat && valid_bo_target)) {
)
)
{
// Normally, we wouldn't want to do this without class checks..but, too many issues can arise if we let enchanter animation pets run rampant // Normally, we wouldn't want to do this without class checks..but, too many issues can arise if we let enchanter animation pets run rampant
if (HasPet()) { if (HasPet()) {
GetPet()->RemoveFromHateList(tar); GetPet()->RemoveFromHateList(tar);

View File

@ -207,11 +207,11 @@ bool Mob::SpellEffect(Mob* caster, uint16 spell_id, float partial, int level_ove
} }
} }
if(IsVirusSpell(spell_id)) { if (IsVirusSpell(spell_id) && buffslot > -1) {
if (!viral_timer.Enabled()) { if (!viral_timer.Enabled()) {
viral_timer.Start(1000); viral_timer.Start(1000);
} }
buffs[buffslot].virus_spread_time = zone->random.Int(GetViralMinSpreadTime(spell_id), GetViralMaxSpreadTime(spell_id)); buffs[buffslot].virus_spread_time = zone->random.Int(GetViralMinSpreadTime(spell_id), GetViralMaxSpreadTime(spell_id));
} }
@ -819,20 +819,20 @@ bool Mob::SpellEffect(Mob* caster, uint16 spell_id, float partial, int level_ove
// define spells with fixed duration // define spells with fixed duration
// charm spells with -1 in field 209 are all of fixed duration, so lets use that instead of spell_ids // charm spells with -1 in field 209 are all of fixed duration, so lets use that instead of spell_ids
if(spells[spell_id].no_resist) if (spells[spell_id].no_resist) {
bBreak = true; bBreak = true;
if (!bBreak)
{
int resistMod = static_cast<int>(partial) + (GetCHA()/25);
resistMod = resistMod > 100 ? 100 : resistMod;
buffs[buffslot].ticsremaining = resistMod * buffs[buffslot].ticsremaining / 100;
} }
if (IsClient() || IsBot()) if (buffslot > -1) {
{ if (!bBreak) {
if(buffs[buffslot].ticsremaining > RuleI(Character, MaxCharmDurationForPlayerCharacter)) int resistMod = static_cast<int>(partial) + (GetCHA() / 25);
resistMod = resistMod > 100 ? 100 : resistMod;
buffs[buffslot].ticsremaining = resistMod * buffs[buffslot].ticsremaining / 100;
}
if (IsOfClientBot() && buffs[buffslot].ticsremaining > RuleI(Character, MaxCharmDurationForPlayerCharacter)) {
buffs[buffslot].ticsremaining = RuleI(Character, MaxCharmDurationForPlayerCharacter); buffs[buffslot].ticsremaining = RuleI(Character, MaxCharmDurationForPlayerCharacter);
}
} }
break; break;
@ -887,8 +887,7 @@ bool Mob::SpellEffect(Mob* caster, uint16 spell_id, float partial, int level_ove
#ifdef SPELL_EFFECT_SPAM #ifdef SPELL_EFFECT_SPAM
snprintf(effect_desc, _EDLEN, "Fear: %+i", effect_value); snprintf(effect_desc, _EDLEN, "Fear: %+i", effect_value);
#endif #endif
if (IsClient() || IsBot()) if (IsOfClientBot() && buffslot > -1) {
{
if (buffs[buffslot].ticsremaining > RuleI(Character, MaxFearDurationForPlayerCharacter)) { if (buffs[buffslot].ticsremaining > RuleI(Character, MaxFearDurationForPlayerCharacter)) {
buffs[buffslot].ticsremaining = RuleI(Character, MaxFearDurationForPlayerCharacter); buffs[buffslot].ticsremaining = RuleI(Character, MaxFearDurationForPlayerCharacter);
} }
@ -902,13 +901,11 @@ bool Mob::SpellEffect(Mob* caster, uint16 spell_id, float partial, int level_ove
} }
CalculateNewFearpoint(); CalculateNewFearpoint();
if (currently_fleeing) if (currently_fleeing) {
{
break; break;
} }
} }
else else if (buffslot > -1) {
{
Stun(buffs[buffslot].ticsremaining * 6000 - (6000 - tic_timer.GetRemainingTime())); Stun(buffs[buffslot].ticsremaining * 6000 - (6000 - tic_timer.GetRemainingTime()));
} }
break; break;
@ -1307,8 +1304,9 @@ bool Mob::SpellEffect(Mob* caster, uint16 spell_id, float partial, int level_ove
#ifdef SPELL_EFFECT_SPAM #ifdef SPELL_EFFECT_SPAM
snprintf(effect_desc, _EDLEN, "Invulnerability"); snprintf(effect_desc, _EDLEN, "Invulnerability");
#endif #endif
if(spell_id==4789) // Touch of the Divine - Divine Save if (spell_id == 4789 && buffslot > -1) { // Touch of the Divine - Divine Save
buffs[buffslot].ticsremaining = spells[spell_id].buff_duration; // Prevent focus/aa buff extension buffs[buffslot].ticsremaining = spells[spell_id].buff_duration;
} // Prevent focus/aa buff extension
SetInvul(true); SetInvul(true);
break; break;
@ -1355,7 +1353,9 @@ bool Mob::SpellEffect(Mob* caster, uint16 spell_id, float partial, int level_ove
#ifdef SPELL_EFFECT_SPAM #ifdef SPELL_EFFECT_SPAM
snprintf(effect_desc, _EDLEN, "Melee Absorb Rune: %+i", effect_value); snprintf(effect_desc, _EDLEN, "Melee Absorb Rune: %+i", effect_value);
#endif #endif
buffs[buffslot].melee_rune = effect_value; if (buffslot > -1) {
buffs[buffslot].melee_rune = effect_value;
}
break; break;
} }
@ -1364,47 +1364,60 @@ bool Mob::SpellEffect(Mob* caster, uint16 spell_id, float partial, int level_ove
#ifdef SPELL_EFFECT_SPAM #ifdef SPELL_EFFECT_SPAM
snprintf(effect_desc, _EDLEN, "Spell Absorb Rune: %+i", effect_value); snprintf(effect_desc, _EDLEN, "Spell Absorb Rune: %+i", effect_value);
#endif #endif
if(effect_value > 0) if (effect_value > 0 && buffslot > -1) {
buffs[buffslot].magic_rune = effect_value; buffs[buffslot].magic_rune = effect_value;
}
break; break;
} }
case SE_MitigateMeleeDamage: case SE_MitigateMeleeDamage:
{ {
buffs[buffslot].melee_rune = spells[spell_id].max_value[i]; if (buffslot > -1) {
buffs[buffslot].melee_rune = spells[spell_id].max_value[i];
}
break; break;
} }
case SE_MeleeThresholdGuard: case SE_MeleeThresholdGuard:
{ {
buffs[buffslot].melee_rune = spells[spell_id].max_value[i]; if (buffslot > -1) {
buffs[buffslot].melee_rune = spells[spell_id].max_value[i];
}
break; break;
} }
case SE_SpellThresholdGuard: case SE_SpellThresholdGuard:
{ {
buffs[buffslot].magic_rune = spells[spell_id].max_value[i]; if (buffslot > -1) {
buffs[buffslot].magic_rune = spells[spell_id].max_value[i];
}
break; break;
} }
case SE_MitigateSpellDamage: case SE_MitigateSpellDamage:
{ {
buffs[buffslot].magic_rune = spells[spell_id].max_value[i]; if (buffslot > -1) {
buffs[buffslot].magic_rune = spells[spell_id].max_value[i];
}
break; break;
} }
case SE_MitigateDotDamage: case SE_MitigateDotDamage:
{ {
buffs[buffslot].dot_rune = spells[spell_id].max_value[i]; if (buffslot > -1) {
buffs[buffslot].dot_rune = spells[spell_id].max_value[i];
}
break; break;
} }
case SE_DistanceRemoval: case SE_DistanceRemoval:
{ {
buffs[buffslot].caston_x = int(GetX()); if (buffslot > -1) {
buffs[buffslot].caston_y = int(GetY()); buffs[buffslot].caston_x = int(GetX());
buffs[buffslot].caston_z = int(GetZ()); buffs[buffslot].caston_y = int(GetY());
buffs[buffslot].caston_z = int(GetZ());
}
break; break;
} }
@ -1434,7 +1447,9 @@ bool Mob::SpellEffect(Mob* caster, uint16 spell_id, float partial, int level_ove
caster->spellbonuses.UnfailingDivinity; caster->spellbonuses.UnfailingDivinity;
} }
buffs[buffslot].ExtraDIChance = mod; if (buffslot > -1) {
buffs[buffslot].ExtraDIChance = mod;
}
break; break;
} }
@ -1694,7 +1709,7 @@ bool Mob::SpellEffect(Mob* caster, uint16 spell_id, float partial, int level_ove
#endif #endif
rooted = true; rooted = true;
if (caster){ if (caster && buffslot > -1) {
buffs[buffslot].RootBreakChance = caster->aabonuses.RootBreakChance + buffs[buffslot].RootBreakChance = caster->aabonuses.RootBreakChance +
caster->itembonuses.RootBreakChance + caster->itembonuses.RootBreakChance +
caster->spellbonuses.RootBreakChance; caster->spellbonuses.RootBreakChance;