Core/Misc: Properly sanitize ReputationSpillover data
Fix an issue added in 024b57bb74 that didn't properly skip ReputationSpillover rows with invalid data.
Fix also a static analysis issue reported by Coverity.
(cherry picked from commit 95b1204798d3ab2a141f81b294b064255c335b8a)
Conflicts:
src/server/game/Globals/ObjectMgr.cpp
This commit is contained in:
1 parent
7870ca8fdc
commit
4c0476bfd7
3 files changed
+16
-27
No files matched your search
@@ -7078,6 +7078,7 @@ void ObjectMgr::LoadReputationSpilloverTemplate()
|
||||
continue;
|
||||
}
|
||||
|
||||
bool invalidSpilloverFaction = false;
|
||||
for (uint32 i = 0; i < MAX_SPILLOVER_FACTIONS; ++i)
|
||||
{
|
||||
if (repTemplate.faction[i])
|
||||
@@ -7087,47 +7088,28 @@ void ObjectMgr::LoadReputationSpilloverTemplate()
|
||||
if (!factionSpillover)
|
||||
{
|
||||
TC_LOG_ERROR("sql.sql", "Spillover faction (faction.dbc) %u does not exist but is used in `reputation_spillover_template` for faction %u, skipping", repTemplate.faction[i], factionId);
|
||||
continue;
|
||||
invalidSpilloverFaction = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (factionSpillover->reputationListID < 0)
|
||||
{
|
||||
TC_LOG_ERROR("sql.sql", "Spillover faction (faction.dbc) %u for faction %u in `reputation_spillover_template` can not be listed for client, and then useless, skipping", repTemplate.faction[i], factionId);
|
||||
continue;
|
||||
invalidSpilloverFaction = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (repTemplate.faction_rank[i] >= MAX_REPUTATION_RANK)
|
||||
{
|
||||
TC_LOG_ERROR("sql.sql", "Rank %u used in `reputation_spillover_template` for spillover faction %u is not valid, skipping", repTemplate.faction_rank[i], repTemplate.faction[i]);
|
||||
continue;
|
||||
invalidSpilloverFaction = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FactionEntry const* factionEntry0 = sFactionStore.LookupEntry(repTemplate.faction[0]);
|
||||
if (repTemplate.faction[0] && !factionEntry0)
|
||||
{
|
||||
TC_LOG_ERROR("sql.sql", "Faction (faction.dbc) %u does not exist but is used in `reputation_spillover_template`", repTemplate.faction[0]);
|
||||
if (invalidSpilloverFaction)
|
||||
continue;
|
||||
}
|
||||
FactionEntry const* factionEntry1 = sFactionStore.LookupEntry(repTemplate.faction[1]);
|
||||
if (repTemplate.faction[1] && !factionEntry1)
|
||||
{
|
||||
TC_LOG_ERROR("sql.sql", "Faction (faction.dbc) %u does not exist but is used in `reputation_spillover_template`", repTemplate.faction[1]);
|
||||
continue;
|
||||
}
|
||||
FactionEntry const* factionEntry2 = sFactionStore.LookupEntry(repTemplate.faction[2]);
|
||||
if (repTemplate.faction[2] && !factionEntry2)
|
||||
{
|
||||
TC_LOG_ERROR("sql.sql", "Faction (faction.dbc) %u does not exist but is used in `reputation_spillover_template`", repTemplate.faction[2]);
|
||||
continue;
|
||||
}
|
||||
FactionEntry const* factionEntry3 = sFactionStore.LookupEntry(repTemplate.faction[3]);
|
||||
if (repTemplate.faction[3] && !factionEntry3)
|
||||
{
|
||||
TC_LOG_ERROR("sql.sql", "Faction (faction.dbc) %u does not exist but is used in `reputation_spillover_template`", repTemplate.faction[3]);
|
||||
continue;
|
||||
}
|
||||
|
||||
_repSpilloverTemplateStore[factionId] = repTemplate;
|
||||
|
||||
|
||||
@@ -297,7 +297,7 @@ bool ReputationMgr::SetReputation(FactionEntry const* factionEntry, int32 standi
|
||||
{
|
||||
// bonuses are already given, so just modify standing by rate
|
||||
int32 spilloverRep = int32(standing * repTemplate->faction_rate[i]);
|
||||
SetOneFactionReputation(sFactionStore.LookupEntry(repTemplate->faction[i]), spilloverRep, incremental);
|
||||
SetOneFactionReputation(sFactionStore.AssertEntry(repTemplate->faction[i]), spilloverRep, incremental);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,6 +87,13 @@ class DBCStorage
|
||||
return (id >= nCount) ? NULL : indexTable.asT[id];
|
||||
}
|
||||
|
||||
T const* AssertEntry(uint32 id) const
|
||||
{
|
||||
T const* entry = LookupEntry(id);
|
||||
ASSERT(entry);
|
||||
return entry;
|
||||
}
|
||||
|
||||
uint32 GetNumRows() const { return nCount; }
|
||||
char const* GetFormat() const { return fmt; }
|
||||
uint32 GetFieldCount() const { return fieldCount; }
|
||||
|
||||
Reference in new issue
Block a user