From ceaee0ec6837454e0588ce451b6c36c2ed746483 Mon Sep 17 00:00:00 2001 From: Eladash Date: Fri, 20 Mar 2020 18:39:04 +0200 Subject: [PATCH] cellSaveData: Clear traces of setList setup from setBuf->buf, add missing memset * Always memset 0 setBuf->buf (to bufSize) before funcStat if the direcory is not new. * Always memset 0 setBuf->buf (to bufSize) if listGet->dirNum became non-zero (listGet->dirListNum can be zero yet memset still occurs) . * Clear traces of setList setup before funcStat (after funcFixed/List, only if listGet->dirNum != 0, callback can hack this value and prevent the memset). --- rpcs3/Emu/Cell/Modules/cellSaveData.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/rpcs3/Emu/Cell/Modules/cellSaveData.cpp b/rpcs3/Emu/Cell/Modules/cellSaveData.cpp index b38044be1d..52edb367c2 100644 --- a/rpcs3/Emu/Cell/Modules/cellSaveData.cpp +++ b/rpcs3/Emu/Cell/Modules/cellSaveData.cpp @@ -613,7 +613,12 @@ static NEVER_INLINE error_code savedata_op(ppu_thread& ppu, u32 operation, u32 v if (entry.name.starts_with(prefix)) { // Count the amount of matches and the amount of listed directories - listGet->dirNum++; // total number of directories + if (!listGet->dirNum++) // total number of directories + { + // Clear buf exactly to bufSize only if dirNum becomes non-zero (regardless of dirListNum) + std::memset(setBuf->buf.get_ptr(), 0, setBuf->bufSize); + } + if (listGet->dirListNum < setBuf->dirListMax) { listGet->dirListNum++; // number of directories in list @@ -690,7 +695,6 @@ static NEVER_INLINE error_code savedata_op(ppu_thread& ppu, u32 operation, u32 v auto& dir = *dir_list++; strcpy_trunc(dir.dirName, entry.dirName); strcpy_trunc(dir.listParam, entry.listParam); - std::memset(dir.reserved, 0, sizeof(dir.reserved)); } s32 selected = -1; @@ -1180,6 +1184,12 @@ static NEVER_INLINE error_code savedata_op(ppu_thread& ppu, u32 operation, u32 v } } + if (listGet->dirNum) + { + // Clear buf exactly to bufSize again after funcFixed/List (for funcStat) + std::memset(setBuf->buf.get_ptr(), 0, setBuf->bufSize); + } + if (selected >= 0) { if (selected + 0u < save_entries.size()) @@ -1253,7 +1263,13 @@ static NEVER_INLINE error_code savedata_op(ppu_thread& ppu, u32 operation, u32 v statGet->fileNum = 0; statGet->fileList.set(setBuf->buf.addr()); statGet->fileListNum = 0; - memset(statGet->reserved, 0, sizeof(statGet->reserved)); + std::memset(statGet->reserved, 0, sizeof(statGet->reserved)); + + if (!save_entry.isNew) + { + // Clear to bufSize if !isNew regardless of fileNum + std::memset(setBuf->buf.get_ptr(), 0, setBuf->bufSize); + } auto file_list = statGet->fileList.get_ptr();