From 889ea5e5aa775246308cd84198505c41aff52c5b Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Sat, 7 Dec 2019 17:42:00 -0800 Subject: [PATCH] Fix memory corruption in romfs build (closes #708) --- stratosphere/ams_mitm/source/fs_mitm/fsmitm_romfs.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/stratosphere/ams_mitm/source/fs_mitm/fsmitm_romfs.cpp b/stratosphere/ams_mitm/source/fs_mitm/fsmitm_romfs.cpp index 9e5ff36ac..56472172f 100644 --- a/stratosphere/ams_mitm/source/fs_mitm/fsmitm_romfs.cpp +++ b/stratosphere/ams_mitm/source/fs_mitm/fsmitm_romfs.cpp @@ -371,8 +371,10 @@ namespace ams::mitm::fs { /* Set name. */ cur_entry->name_size = name_size; if (name_size) { - std::memset(cur_entry->name + util::AlignDown(name_size, 4), 0, 4); std::memcpy(cur_entry->name, cur_file->path.get() + cur_file->cur_path_ofs, name_size); + for (size_t i = name_size; i < util::AlignUp(name_size, 4); i++) { + cur_entry->name[i] = 0; + } } /* Emplace a source. */ @@ -418,8 +420,10 @@ namespace ams::mitm::fs { /* Set name. */ cur_entry->name_size = name_size; if (name_size) { - std::memset(cur_entry->name + util::AlignDown(name_size, 4), 0, 4); std::memcpy(cur_entry->name, cur_dir->path.get() + cur_dir->cur_path_ofs, name_size); + for (size_t i = name_size; i < util::AlignUp(name_size, 4); i++) { + cur_entry->name[i] = 0; + } } }