aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorariel- <ariel-@users.noreply.github.com>2017-04-11 23:23:52 -0300
committerfunjoker <funjoker109@gmail.com>2020-04-27 12:25:52 +0200
commit0d8c1b49b82081eac42ca68ec0d9ee199bb1eda3 (patch)
treea9c3ffe640a2d1b650540ff15852cb08f4c83817
parent7c571c5b0a983de9b6f67de55cf6a15f8bac4868 (diff)
Core/Creature: fix integer overflow in Creature::Update leading to endless thrashing of characters database
Closes #19182 (cherry picked from commit 66755eecf117d21504b13a86410aa01cfc44c3ba)
-rw-r--r--src/server/game/Entities/Creature/Creature.cpp13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp
index 4bbb29d43c1..1e60264c8aa 100644
--- a/src/server/game/Entities/Creature/Creature.cpp
+++ b/src/server/game/Entities/Creature/Creature.cpp
@@ -622,7 +622,18 @@ void Creature::Update(uint32 diff)
if (targetGuid == dbtableHighGuid) // if linking self, never respawn (check delayed to next day)
SetRespawnTime(DAY);
else
- m_respawnTime = (now > linkedRespawntime ? now : linkedRespawntime) + urand(5, MINUTE); // else copy time from master and add a little
+ {
+ // else copy time from master and add a little
+ time_t baseRespawnTime = std::max(linkedRespawntime, now);
+ time_t const offset = urand(5, MINUTE);
+
+ // linked guid can be a boss, uses std::numeric_limits<time_t>::max to never respawn in that instance
+ // we shall inherit it instead of adding and causing an overflow
+ if (baseRespawnTime <= std::numeric_limits<time_t>::max() - offset)
+ m_respawnTime = baseRespawnTime + offset;
+ else
+ m_respawnTime = std::numeric_limits<time_t>::max();
+ }
SaveRespawnTime(); // also save to DB immediately
}
}