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:
kalaposfos13 2026-02-16 21:56:35 +01:00 committed by GitHub
parent 547198af6f
commit 3a99051df9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 8 additions and 4 deletions

View File

@ -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 "";
}

View File

@ -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:

View File

@ -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() {