From c3c2bb7ad81f6b38fe072683d430d64d163c521e Mon Sep 17 00:00:00 2001 From: brian218 Date: Wed, 18 Jan 2023 10:23:06 +0800 Subject: [PATCH] USIO: Do not crash simply due to invalid commands --- rpcs3/Emu/Io/usio.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/rpcs3/Emu/Io/usio.cpp b/rpcs3/Emu/Io/usio.cpp index ee750102a2..f6034de14a 100644 --- a/rpcs3/Emu/Io/usio.cpp +++ b/rpcs3/Emu/Io/usio.cpp @@ -76,6 +76,7 @@ usb_device_usio::usb_device_usio(const std::array& location) .wMaxPacketSize = 0x0008, .bInterval = 16})); + g_fxo->get().backup_memory.clear(); g_fxo->get().backup_memory.resize(0xB8); g_fxo->get().last_game_status.clear(); g_fxo->get().last_game_status.resize(0x28); @@ -512,7 +513,12 @@ void usb_device_usio::interrupt_transfer(u32 buf_size, u8* buf, u32 endpoint, Us } // Commands - ensure(buf_size == 6, "Expected a command but buf_size != 6"); + if (buf_size != 6) + { + usio_log.error("Expected a command but buf_size != 6"); + return; + } + usio_channel = buf[0] & 0xF; usio_register = *reinterpret_cast*>(&buf[2]); usio_length = *reinterpret_cast*>(&buf[4]); @@ -520,7 +526,11 @@ void usb_device_usio::interrupt_transfer(u32 buf_size, u8* buf, u32 endpoint, Us if ((buf[0] & USIO_COMMAND_WRITE) == USIO_COMMAND_WRITE) { usio_log.trace("UsioWrite(Channel: 0x%02X, Register: 0x%04X, Length: 0x%04X)", usio_channel, usio_register, usio_length); - ensure(((~(usio_register >> 8)) & 0xF0) == buf[1]); + if (((~(usio_register >> 8)) & 0xF0) != buf[1]) + { + usio_log.error("Invalid UsioWrite command"); + return; + } expecting_data = true; usio_data.clear(); }