[Crash Fix] Fix Possible Crash in HateList::Find (#4027)

# Notes
- We were not doing any pointer validation, so we were causing crashes in some cases.
- Example: http://spire.akkadius.com/dev/release/22.43.2?id=19163
This commit is contained in:
Alex King 2024-01-28 03:44:04 -05:00 committed by GitHub
parent 5b43bf4a5e
commit 9ee16f8bf7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 8 deletions

View File

@ -80,15 +80,18 @@ bool HateList::IsEntOnHateList(Mob *mob)
return false; return false;
} }
struct_HateList *HateList::Find(Mob *in_entity) struct_HateList* HateList::Find(Mob* m)
{ {
auto iterator = list.begin(); if (!m) {
while (iterator != list.end()) return nullptr;
{
if ((*iterator)->entity_on_hatelist == in_entity)
return (*iterator);
++iterator;
} }
for (auto* e : list) {
if (e->entity_on_hatelist && e->entity_on_hatelist == m) {
return e;
}
}
return nullptr; return nullptr;
} }

View File

@ -89,7 +89,7 @@ public:
protected: protected:
struct_HateList *Find(Mob *ent); struct_HateList* Find(Mob* m);
private: private:
std::list<struct_HateList *> list; std::list<struct_HateList *> list;
Mob *hate_owner; Mob *hate_owner;