aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgameblabla2019-07-18 02:09:56 +0200
committergameblabla2019-07-18 02:09:56 +0200
commita66d30585863c4fabbb724a69e30e3282c39bdc3 (patch)
treed4352e3b6443608fb51964e0424deb26a54ab3e6
parentb29f3be0ac3fb01453eae2dabf8471b262881b30 (diff)
downloadpcsx_rearmed-a66d30585863c4fabbb724a69e30e3282c39bdc3.tar.gz
pcsx_rearmed-a66d30585863c4fabbb724a69e30e3282c39bdc3.tar.bz2
pcsx_rearmed-a66d30585863c4fabbb724a69e30e3282c39bdc3.zip
psxbios: Fix out-of-bounds issue.
Make sure to return 0xff is no TCBs are available. Thanks senquack for the proper fix.
-rw-r--r--libpcsxcore/psxbios.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/libpcsxcore/psxbios.c b/libpcsxcore/psxbios.c
index 9341b0d..5bff23e 100644
--- a/libpcsxcore/psxbios.c
+++ b/libpcsxcore/psxbios.c
@@ -1667,8 +1667,20 @@ void psxBios_OpenTh() { // 0e
int th;
for (th=1; th<8; th++)
+ {
if (Thread[th].status == 0) break;
+ }
+ if (th == 8) {
+ // Feb 2019 - Added out-of-bounds fix caught by cppcheck:
+ // When no free TCB is found, return 0xffffffff according to Nocash doc.
+#ifdef PSXBIOS_LOG
+ PSXBIOS_LOG("\t%s() WARNING! No Free TCBs found!\n", __func__);
+#endif
+ v0 = 0xffffffff;
+ pc0 = ra;
+ return;
+ }
#ifdef PSXBIOS_LOG
PSXBIOS_LOG("psxBios_%s: %x\n", biosB0n[0x0e], th);
#endif