From 1518b8f914c389538b2efcaba3bce64707278b74 Mon Sep 17 00:00:00 2001 From: Erik Schilling Date: Fri, 24 Apr 2015 17:28:57 +0200 Subject: Fix crash if the client sends garbage public id values Indexing an array with a negative int as index is no good idea... --- src/game-server/mapcomposite.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/game-server/mapcomposite.cpp b/src/game-server/mapcomposite.cpp index deb43b4e..41073b3c 100644 --- a/src/game-server/mapcomposite.cpp +++ b/src/game-server/mapcomposite.cpp @@ -403,12 +403,16 @@ void MapContent::deallocate(Entity *obj) */ Entity *MapContent::findEntityById(int publicId) const { + if (publicId < 0) { + return nullptr; + } + if (ObjectBucket *b = buckets[publicId / 256]) { const int bucketIndex = publicId % 256; if (b->isAllocated(bucketIndex)) return b->objects[bucketIndex]; } - return 0; + return nullptr; } static void addZone(MapRegion &r, unsigned z) -- cgit v1.2.3-60-g2f50