From a31194a877b2b0718c79cc51171ef839b4d4bcbe Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Sun, 8 Jun 2014 13:03:03 +0200 Subject: [PATCH] Add some sanity checks when looking up syscalls. This may avoid crashing the emu when it starts executing junk (still not good of course, heh). --- Core/HLE/HLE.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Core/HLE/HLE.cpp b/Core/HLE/HLE.cpp index d77fb20efb..05fae66781 100644 --- a/Core/HLE/HLE.cpp +++ b/Core/HLE/HLE.cpp @@ -477,9 +477,16 @@ const HLEFunction *GetSyscallInfo(MIPSOpcode op) u32 callno = (op >> 6) & 0xFFFFF; //20 bits int funcnum = callno & 0xFFF; int modulenum = (callno & 0xFF000) >> 12; - if (funcnum == 0xfff) - { - ERROR_LOG(HLE,"Unknown syscall: Module: %s", modulenum > (int) moduleDB.size() ? "(unknown)" : moduleDB[modulenum].name); + if (funcnum == 0xfff) { + ERROR_LOG(HLE, "Unknown syscall: Module: %s", modulenum > (int) moduleDB.size() ? "(unknown)" : moduleDB[modulenum].name); + return NULL; + } + if (modulenum >= moduleDB.size()) { + ERROR_LOG(HLE, "Syscall had bad module number %i - probably executing garbage", modulenum); + return NULL; + } + if (funcnum >= moduleDB[modulenum].numFunctions) { + ERROR_LOG(HLE, "Syscall had bad function number %i in module %i - probably executing garbage", funcnum, modulenum); return NULL; } return &moduleDB[modulenum].funcTable[funcnum]; @@ -525,7 +532,7 @@ void CallSyscall(MIPSOpcode op) CallSyscallWithoutFlags(info); } else - ERROR_LOG_REPORT(HLE, "Unimplemented HLE function %s", info->name); + ERROR_LOG_REPORT(HLE, "Unimplemented HLE function %s", info->name ? info->name : "(???)"); if (g_Config.bShowDebugStats) {