From 73f46089cceb4c2f125c8b8badfbaef971a0e1a0 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Wed, 3 Jul 2019 13:11:48 +0300 Subject: [PATCH] - added validation of LevelCompatibility.Apply() signature --- src/maploader/compatibility.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/maploader/compatibility.cpp b/src/maploader/compatibility.cpp index 63586a1a71..bf9d389c7d 100644 --- a/src/maploader/compatibility.cpp +++ b/src/maploader/compatibility.cpp @@ -54,6 +54,7 @@ #include "actor.h" #include "p_setup.h" #include "maploader/maploader.h" +#include "types.h" // MACROS ------------------------------------------------------------------ @@ -365,11 +366,21 @@ void MapLoader::SetCompatibilityParams(FName checksum) if (cls->IsDescendantOf(RUNTIME_CLASS(DLevelCompatibility))) { PFunction *const func = dyn_cast(cls->FindSymbol("Apply", false)); - if (func != nullptr) + if (func == nullptr) { - VMValue param[] = { lc, checksum.GetIndex(), &Level->MapName }; - VMCall(func->Variants[0].Implementation, param, 3, nullptr, 0); + Printf("Missing 'Apply' method in class '%s', level compatibility object ignored\n", cls->TypeName.GetChars()); + continue; } + + auto argTypes = func->Variants[0].Proto->ArgumentTypes; + if (argTypes.Size() != 3 || argTypes[1] != TypeName || argTypes[2] != TypeString) + { + Printf("Wrong signature of 'Apply' method in class '%s', level compatibility object ignored\n", cls->TypeName.GetChars()); + continue; + } + + VMValue param[] = { lc, checksum.GetIndex(), &Level->MapName }; + VMCall(func->Variants[0].Implementation, param, 3, nullptr, 0); } } }