From 62bac1d612a83e9a1823e761dfd16b5cef991e25 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Tue, 30 May 2017 18:09:51 +0300 Subject: [PATCH] Added check for nullptr to CLSS and META instructions of scripting VM https://forum.zdoom.org/viewtopic.php?t=56667 --- src/scripting/vm/vmexec.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/scripting/vm/vmexec.h b/src/scripting/vm/vmexec.h index 7e8a53a6a..d5b8ba6b1 100644 --- a/src/scripting/vm/vmexec.h +++ b/src/scripting/vm/vmexec.h @@ -37,6 +37,16 @@ #error vmexec.h must not be #included outside vmexec.cpp. Use vm.h instead. #endif +static PClass* GetClass(void* ptr) +{ + if (nullptr == ptr) + { + ThrowAbortException(X_READ_NIL, nullptr); + } + + return static_cast(ptr)->GetClass(); +} + static int Exec(VMFrameStack *stack, const VMOP *pc, VMReturn *ret, int numret) { #if COMPGOTO @@ -140,12 +150,12 @@ static int Exec(VMFrameStack *stack, const VMOP *pc, VMReturn *ret, int numret) OP(CLSS): ASSERTA(a); ASSERTA(B); - reg.a[a] = ((DObject*)reg.a[B])->GetClass(); // I wish this could be done without a special opcode but there's really no good way to guarantee initialization of the Class pointer... + reg.a[a] = GetClass(reg.a[B]); NEXTOP; OP(META): ASSERTA(a); ASSERTA(B); - reg.a[a] = ((DObject*)reg.a[B])->GetClass()->Meta; // I wish this could be done without a special opcode but there's really no good way to guarantee initialization of the Class pointer... + reg.a[a] = GetClass(reg.a[B])->Meta; NEXTOP; OP(LB):