[Crash] Fix out of bound arrays, other potential crashes (#3166)

This commit is contained in:
Aeadoin 2023-04-01 12:44:41 -04:00 committed by GitHub
parent 0d509a7f3a
commit 0df84e1ee6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 34 additions and 24 deletions

View File

@ -1963,7 +1963,7 @@ void Client::TogglePassiveAlternativeAdvancement(const AA::Rank &rank, uint32 ab
AA::Rank *rank_next = zone->GetAlternateAdvancementRank(rank.next_id);
//Add checks for any special cases for toggle.
if (IsEffectinAlternateAdvancementRankEffects(*rank_next, SE_Weapon_Stance)) {
if (rank_next && IsEffectinAlternateAdvancementRankEffects(*rank_next, SE_Weapon_Stance)) {
weaponstance.aabonus_enabled = true;
ApplyWeaponsStance();
}
@ -2003,7 +2003,7 @@ bool Client::UseTogglePassiveHotkey(const AA::Rank &rank) {
else if (rank.prev_id != -1) {//Check when effect is Enabled.
AA::Rank *rank_prev = zone->GetAlternateAdvancementRank(rank.prev_id);
if (IsEffectInSpell(rank_prev->spell, SE_Buy_AA_Rank)) {
if (rank_prev && IsEffectInSpell(rank_prev->spell, SE_Buy_AA_Rank)) {
return true;
}
}

View File

@ -904,8 +904,9 @@ bool Mob::IsBeneficialAllowed(Mob *target)
{
return false;
}
else if(mob2->IsBot())
else if (mob2 && mob2->IsBot()) {
return true;
}
}
else if(_NPC(mob1))
{

View File

@ -1484,7 +1484,6 @@ bool Mob::Attack(Mob* other, int Hand, bool bRiposte, bool IsStrikethrough, bool
if (
(IsCasting() && GetClass() != BARD && !IsFromSpell)
|| other == nullptr
|| ((IsClient() && CastToClient()->dead) || (other->IsClient() && other->CastToClient()->dead))
|| (GetHP() < 0)
|| (!IsAttackAllowed(other))

View File

@ -1802,8 +1802,9 @@ void Mob::ApplyAABonuses(const AA::Rank &rank, StatBonuses *newbon)
case SE_Damage_Taken_Position_Mod:
{
//Mitigate if damage taken from behind base2 = 0, from front base2 = 1
if (limit_value < 0 || limit_value > 2)
if (limit_value < 0 || limit_value >= 2) {
break;
}
else if (base_value < 0 && newbon->Damage_Taken_Position_Mod[limit_value] > base_value)
newbon->Damage_Taken_Position_Mod[limit_value] = base_value;
else if (base_value > 0 && newbon->Damage_Taken_Position_Mod[limit_value] < base_value)
@ -1813,8 +1814,9 @@ void Mob::ApplyAABonuses(const AA::Rank &rank, StatBonuses *newbon)
case SE_Melee_Damage_Position_Mod:
{
if (limit_value < 0 || limit_value > 2)
if (limit_value < 0 || limit_value >= 2) {
break;
}
else if (base_value < 0 && newbon->Melee_Damage_Position_Mod[limit_value] > base_value)
newbon->Melee_Damage_Position_Mod[limit_value] = base_value;
else if (base_value > 0 && newbon->Melee_Damage_Position_Mod[limit_value] < base_value)
@ -1825,9 +1827,9 @@ void Mob::ApplyAABonuses(const AA::Rank &rank, StatBonuses *newbon)
case SE_Damage_Taken_Position_Amt:
{
//Mitigate if damage taken from behind base2 = 0, from front base2 = 1
if (limit_value < 0 || limit_value > 2)
if (limit_value < 0 || limit_value >= 2) {
break;
}
newbon->Damage_Taken_Position_Amt[limit_value] += base_value;
break;
}
@ -1835,8 +1837,9 @@ void Mob::ApplyAABonuses(const AA::Rank &rank, StatBonuses *newbon)
case SE_Melee_Damage_Position_Amt:
{
//Mitigate if damage taken from behind base2 = 0, from front base2 = 1
if (limit_value < 0 || limit_value > 2)
if (limit_value < 0 || limit_value >= 2) {
break;
}
newbon->Melee_Damage_Position_Amt[limit_value] += base_value;
break;
@ -3884,8 +3887,9 @@ void Mob::ApplySpellsBonuses(uint16 spell_id, uint8 casterlevel, StatBonuses *ne
case SE_Damage_Taken_Position_Mod:
{
//Mitigate if damage taken from behind base2 = 0, from front base2 = 1
if (limit_value < 0 || limit_value > 2)
if (limit_value < 0 || limit_value >= 2) {
break;
}
if (AdditiveWornBonus)
new_bonus->Damage_Taken_Position_Mod[limit_value] += effect_value;
else if (effect_value < 0 && new_bonus->Damage_Taken_Position_Mod[limit_value] > effect_value)
@ -3898,8 +3902,9 @@ void Mob::ApplySpellsBonuses(uint16 spell_id, uint8 casterlevel, StatBonuses *ne
case SE_Melee_Damage_Position_Mod:
{
//Increase damage by percent from behind base2 = 0, from front base2 = 1
if (limit_value < 0 || limit_value > 2)
if (limit_value < 0 || limit_value >= 2) {
break;
}
if (AdditiveWornBonus)
new_bonus->Melee_Damage_Position_Mod[limit_value] += effect_value;
else if (effect_value < 0 && new_bonus->Melee_Damage_Position_Mod[limit_value] > effect_value)
@ -3912,8 +3917,9 @@ void Mob::ApplySpellsBonuses(uint16 spell_id, uint8 casterlevel, StatBonuses *ne
case SE_Damage_Taken_Position_Amt:
{
//Mitigate if damage taken from behind base2 = 0, from front base2 = 1
if (limit_value < 0 || limit_value > 2)
if (limit_value < 0 || limit_value >= 2) {
break;
}
new_bonus->Damage_Taken_Position_Amt[limit_value] += effect_value;
break;
@ -3922,8 +3928,9 @@ void Mob::ApplySpellsBonuses(uint16 spell_id, uint8 casterlevel, StatBonuses *ne
case SE_Melee_Damage_Position_Amt:
{
//Mitigate if damage taken from behind base2 = 0, from front base2 = 1
if (limit_value < 0 || limit_value > 2)
if (limit_value < 0 || limit_value >= 2) {
break;
}
new_bonus->Melee_Damage_Position_Amt[limit_value] += effect_value;
break;

View File

@ -1936,6 +1936,11 @@ void Bot::AI_Process()
#define NOT_PASSIVE (GetBotStance() != EQ::constants::stancePassive)
Client* bot_owner = (GetBotOwner() && GetBotOwner()->IsClient() ? GetBotOwner()->CastToClient() : nullptr);
if (!bot_owner) {
return;
}
auto raid = entity_list.GetRaidByBotName(GetName());
uint32 r_group = RAID_GROUPLESS;
if (raid) {
@ -2983,7 +2988,7 @@ void Bot::HealRotationChecks() {
bool Bot::IsAIProcessValid(const Client* bot_owner, const Group* bot_group, const Raid* raid) {
if (!bot_owner || !bot_group && !raid || !IsAIControlled()) {
if (!bot_owner || (!bot_group && !raid) || !IsAIControlled()) {
return false;
}

View File

@ -392,8 +392,7 @@ Corpse::Corpse(Client* client, int32 in_rezexp) : Mob (
/* Check Rule to see if we can leave corpses */
if (
!RuleB(Character, LeaveNakedCorpses) ||
RuleB(Character, LeaveCorpses) &&
(!RuleB(Character, LeaveNakedCorpses) || RuleB(Character, LeaveCorpses)) &&
GetLevel() >= RuleI(Character, DeathItemLossLevel)
) {
// cash

View File

@ -222,7 +222,7 @@ void Doors::HandleClick(Client *sender, uint8 trigger)
}
}
if (m_dz_switch_id != 0) {
if (sender && m_dz_switch_id != 0) {
sender->UpdateTasksOnTouchSwitch(m_dz_switch_id);
if (sender->TryMovePCDynamicZoneSwitch(m_dz_switch_id)) {
safe_delete(outapp);

View File

@ -545,7 +545,6 @@ bool Group::UpdatePlayer(Mob* update) {
}
void Group::MemberZoned(Mob* removemob) {
uint32 i;
if (!removemob) {
return;
@ -557,21 +556,21 @@ void Group::MemberZoned(Mob* removemob) {
//should NOT clear the name, it is used for world communication.
for (auto & m : members) {
if (m && (m == removemob || m->IsBot() && m->CastToBot()->GetBotOwner() == removemob)) {
if (m && (m == removemob || (m->IsBot() && m->CastToBot()->GetBotOwner() == removemob))) {
m = nullptr;
}
}
if (removemob->IsClient() && HasRole(removemob, RoleAssist)) {
SetGroupAssistTarget(0);
SetGroupAssistTarget(nullptr);
}
if (removemob->IsClient() && HasRole(removemob, RoleTank)) {
SetGroupTankTarget(0);
SetGroupTankTarget(nullptr);
}
if (removemob->IsClient() && HasRole(removemob, RolePuller)) {
SetGroupPullerTarget(0);
SetGroupPullerTarget(nullptr);
}
if (removemob->IsClient() && removemob == mentoree) {

View File

@ -631,7 +631,7 @@ uint32 Raid::GetPlayerIndex(Client *c)
Client *Raid::GetClientByIndex(uint16 index)
{
if (index > MAX_RAID_MEMBERS) {
if (index >= MAX_RAID_MEMBERS) {
return nullptr;
}
@ -2204,4 +2204,4 @@ void Raid::SetNewRaidLeader(uint32 i)
}
}
}
}
}