Skip to content

Commit

Permalink
VFS: Fix some potential .back() segfaults
Browse files Browse the repository at this point in the history
  • Loading branch information
Megamouse committed Jan 25, 2024
1 parent 74cd12d commit ddcc6dc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Utilities/File.cpp
Expand Up @@ -772,7 +772,7 @@ bool fs::create_path(const std::string& path)

#ifdef _WIN32
// Workaround: don't call is_dir with naked drive letter
if (parent.size() < path.size() && parent.back() != ':' && !is_dir(parent) && !create_path(parent))
if (parent.size() < path.size() && (parent.empty() || (parent.back() != ':' && !is_dir(parent) && !create_path(parent))))
#else
if (parent.size() < path.size() && !is_dir(parent) && !create_path(parent))
#endif
Expand Down
11 changes: 10 additions & 1 deletion rpcs3/Emu/vfs_config.cpp
Expand Up @@ -45,7 +45,11 @@ std::string cfg_vfs::get(const std::string& _cfg, const std::string& def, std::s
path = fmt::replace_all(path, "$(EmulatorDir)", emu_dir);

// Check if path does not end with a delimiter
if (path.back() != fs::delim[0] && path.back() != fs::delim[1])
if (path.empty())
{
vfs_log.error("VFS config path empty (_cfg='%s', def='%s', emu_dir='%s')", _cfg, def, emu_dir);
}
else if (path.back() != fs::delim[0] && path.back() != fs::delim[1])
{
path += '/';
}
Expand Down Expand Up @@ -74,6 +78,11 @@ cfg::device_info cfg_vfs::get_device_info(const cfg::device_entry& _cfg, std::st
def_path = def_it->second.path;
}

if (info.path.empty() && def_path.empty())
{
return {};
}

info.path = get(info.path, def_path, emu_dir);
return info;
}
Expand Down
1 change: 1 addition & 0 deletions rpcs3/rpcs3qt/vfs_dialog_usb_input.cpp
Expand Up @@ -11,6 +11,7 @@ vfs_dialog_usb_input::vfs_dialog_usb_input(const QString& name, const cfg::devic
: QDialog(parent), m_gui_settings(std::move(_gui_settings)), m_gui_save(gui::fs_dev_usb_list)
{
ensure(!!info);
ensure(!name.isEmpty());
ensure(name.back() >= '0' && name.back() <= '7');

setWindowTitle(tr("Edit %0").arg(name));
Expand Down

0 comments on commit ddcc6dc

Please sign in to comment.