mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2026-04-10 03:31:30 -06:00
filesystem: fix crashes caused by returning a pointer from an std::vector (#4043)
Co-authored-by: Stephen Miller <56742918+StevenMiller123@users.noreply.github.com>
This commit is contained in:
parent
547198af6f
commit
3a99051df9
@ -55,7 +55,7 @@ std::filesystem::path MntPoints::GetHostPath(std::string_view path, bool* is_rea
|
||||
if (path.length() > 255)
|
||||
return "";
|
||||
|
||||
const MntPair* mount = GetMount(corrected_path);
|
||||
const std::optional<MntPair> mount = GetMount(corrected_path);
|
||||
if (!mount) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
|
||||
#include <atomic>
|
||||
#include <mutex>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <tsl/robin_map.h>
|
||||
@ -58,14 +59,17 @@ public:
|
||||
return it == m_mnt_pairs.end() ? nullptr : &*it;
|
||||
}
|
||||
|
||||
const MntPair* GetMount(const std::string& guest_path) {
|
||||
const std::optional<MntPair> GetMount(const std::string& guest_path) {
|
||||
std::scoped_lock lock{m_mutex};
|
||||
const auto it = std::ranges::find_if(m_mnt_pairs, [&](const auto& mount) {
|
||||
// When doing starts-with check, add a trailing slash to make sure we don't match
|
||||
// against only part of the mount path.
|
||||
return guest_path == mount.mount || guest_path.starts_with(mount.mount + "/");
|
||||
});
|
||||
return it == m_mnt_pairs.end() ? nullptr : &*it;
|
||||
if (it == m_mnt_pairs.end()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return *it;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@ -105,7 +105,7 @@ SaveInstance::SaveInstance(int slot_num, Libraries::UserService::OrbisUserServic
|
||||
mount_point = "/savedata" + std::to_string(slot_num);
|
||||
|
||||
this->exists = fs::exists(param_sfo_path);
|
||||
this->mounted = g_mnt->GetMount(mount_point) != nullptr;
|
||||
this->mounted = g_mnt->GetMount(mount_point) != std::nullopt;
|
||||
}
|
||||
|
||||
SaveInstance::~SaveInstance() {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user