aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjackpoz <giacomopoz@gmail.com>2015-01-31 22:59:21 +0100
committerjackpoz <giacomopoz@gmail.com>2015-01-31 22:59:21 +0100
commit95b1204798d3ab2a141f81b294b064255c335b8a (patch)
tree2bce20cdd58a44618534b47cea40351402655c46 /src
parenta7ca78b2fe12c68e561782416bf5726410a3c01b (diff)
Core/Misc: Properly sanitize ReputationSpillover data
Fix an issue added in 024b57bb74a664cd515cf0822d4b8e939a91fe03 that didn't properly skip ReputationSpillover rows with invalid data. Fix also a static analysis issue reported by Coverity.
Diffstat (limited to 'src')
-rw-r--r--src/server/game/Globals/ObjectMgr.cpp40
-rw-r--r--src/server/game/Reputation/ReputationMgr.cpp2
-rw-r--r--src/server/shared/DataStores/DBCStore.h7
3 files changed, 16 insertions, 33 deletions
diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp
index 202165ffd57..25d6512acaf 100644
--- a/src/server/game/Globals/ObjectMgr.cpp
+++ b/src/server/game/Globals/ObjectMgr.cpp
@@ -6801,6 +6801,7 @@ void ObjectMgr::LoadReputationSpilloverTemplate()
continue;
}
+ bool invalidSpilloverFaction = false;
for (uint32 i = 0; i < MAX_SPILLOVER_FACTIONS; ++i)
{
if (repTemplate.faction[i])
@@ -6810,53 +6811,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->CanHaveReputation())
{
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]);
- 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]);
+ if (invalidSpilloverFaction)
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;
- }
- FactionEntry const* factionEntry4 = sFactionStore.LookupEntry(repTemplate.faction[4]);
- if (repTemplate.faction[4] && !factionEntry4)
- {
- TC_LOG_ERROR("sql.sql", "Faction (faction.dbc) %u does not exist but is used in `reputation_spillover_template`", repTemplate.faction[4]);
- continue;
- }
_repSpilloverTemplateStore[factionId] = repTemplate;
diff --git a/src/server/game/Reputation/ReputationMgr.cpp b/src/server/game/Reputation/ReputationMgr.cpp
index b77f8f50835..92a41e8c6a6 100644
--- a/src/server/game/Reputation/ReputationMgr.cpp
+++ b/src/server/game/Reputation/ReputationMgr.cpp
@@ -278,7 +278,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);
}
}
}
diff --git a/src/server/shared/DataStores/DBCStore.h b/src/server/shared/DataStores/DBCStore.h
index abc64c17220..d9cd8472fa7 100644
--- a/src/server/shared/DataStores/DBCStore.h
+++ b/src/server/shared/DataStores/DBCStore.h
@@ -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; }