From e0d24f242b4cdc81a11cbf82a63f8203d1efa243 Mon Sep 17 00:00:00 2001 From: Kp Date: Sat, 19 Nov 2016 17:24:53 +0000 Subject: [PATCH] Fix uninitialized signature access `obj_get_signature()` examines all objects with a type other than `OBJ_NONE` to find an unused signature. `load_game_data()`->`read_object()` set an object's type before calling `obj_get_signature()`, so `obj_get_signature()` would consider the uninitialized signature of the newly loaded object for exclusion. Reorder the initialization to compute the signature before the object is given a type, then store the signature on the object after the poison bytes (if any) are written. --- similar/main/gamesave.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/similar/main/gamesave.cpp b/similar/main/gamesave.cpp index fe2a1dc78..a055faf3f 100644 --- a/similar/main/gamesave.cpp +++ b/similar/main/gamesave.cpp @@ -352,7 +352,9 @@ namespace dsx { static void read_object(const vobjptr_t obj,PHYSFS_File *f,int version) { const auto poison_obj = reinterpret_cast(&*obj); + const auto signature = obj_get_signature(); DXX_POISON_MEMORY(poison_obj, sizeof(*obj), 0xfd); + obj->signature = signature; obj->type = PHYSFSX_readByte(f); obj->id = PHYSFSX_readByte(f); @@ -884,7 +886,6 @@ static int load_game_data(PHYSFS_File *LoadFile) { const auto &&o = vobjptr(&i); read_object(o, LoadFile, game_top_fileinfo_version); - i.signature = obj_get_signature(); verify_object(o); } }