[FS] Add app data folder, add path safety checks

This commit is contained in:
wheremyfoodat 2023-01-16 01:06:43 +02:00
parent c16bf5c8aa
commit b1f2be98fa
6 changed files with 77 additions and 12 deletions

View file

@ -1,9 +1,16 @@
#include "fs/archive_ext_save_data.hpp"
#include <memory>
namespace fs = std::filesystem;
bool ExtSaveDataArchive::openFile(const FSPath& path) {
if (path.type != PathType::Binary) {
Helpers::panic("ExtSaveData accessed with a non-binary path in OpenFile. Type: %d", path.type);
if (path.type == PathType::UTF16) {
if (!isPathSafe<PathType::UTF16>(path))
Helpers::panic("Unsafe path in ExtSaveData::OpenFile");
fs::path p = IOFile::getAppData() / "NAND";
p += fs::path(path.utf16_string).make_preferred();
return false;
}
Helpers::panic("ExtSaveDataArchive::OpenFile: Failed");
@ -15,11 +22,6 @@ ArchiveBase* ExtSaveDataArchive::openArchive(const FSPath& path) {
Helpers::panic("ExtSaveData accessed with an invalid path in OpenArchive");
}
u32 mediaType = *(u32*)&path.binary[0];
u64 saveID = *(u64*)&path.binary[4]; // TODO: Get rid of UB here.
Helpers::panic("ExtSaveData: media type = %d\n", mediaType);
return this;
}