summaryrefslogtreecommitdiff
path: root/Source/Core
diff options
context:
space:
mode:
authorPierre Bourdon <delroth@gmail.com>2017-08-06 22:18:20 +0200
committerPierre Bourdon <delroth@gmail.com>2017-08-15 22:35:45 +0200
commit2f5ddf12a9058cef80f17a1fc3635fc2b3f46c18 (patch)
tree5d071a7a9a7d519b151be3e12bd2e49f95467ad9 /Source/Core
parent425cf18bf7973a5b23607bf7827421f28911c584 (diff)
WFS: Normalize paths before opening.
Diffstat (limited to 'Source/Core')
-rw-r--r--Source/Core/Core/IOS/WFS/WFSSRV.cpp24
-rw-r--r--Source/Core/Core/IOS/WFS/WFSSRV.h2
2 files changed, 22 insertions, 4 deletions
diff --git a/Source/Core/Core/IOS/WFS/WFSSRV.cpp b/Source/Core/Core/IOS/WFS/WFSSRV.cpp
index 1f82768ad4..6ff55a8e66 100644
--- a/Source/Core/Core/IOS/WFS/WFSSRV.cpp
+++ b/Source/Core/Core/IOS/WFS/WFSSRV.cpp
@@ -135,7 +135,7 @@ IPCCommandResult WFSSRV::IOCtl(const IOCtlRequest& request)
u16 path_len = Memory::Read_U16(request.buffer_in + 0x20);
std::string path = Memory::GetString(request.buffer_in + 0x22, path_len);
- path = ExpandPath(path);
+ path = NormalizePath(path);
u16 fd = GetNewFileDescriptor();
FileDescriptor* fd_obj = &m_fds[fd];
@@ -204,7 +204,7 @@ IPCCommandResult WFSSRV::IOCtl(const IOCtlRequest& request)
return GetDefaultReply(return_error_code);
}
-std::string WFSSRV::ExpandPath(const std::string& path) const
+std::string WFSSRV::NormalizePath(const std::string& path) const
{
std::string expanded;
if (!path.empty() && path[0] == '~')
@@ -219,7 +219,25 @@ std::string WFSSRV::ExpandPath(const std::string& path) const
{
expanded = path;
}
- return expanded;
+
+ std::vector<std::string> components = SplitString(expanded, '/');
+ std::vector<std::string> normalized_components;
+ for (const auto& component : components)
+ {
+ if (component.empty() || component == ".")
+ {
+ continue;
+ }
+ else if (component == ".." && !normalized_components.empty())
+ {
+ normalized_components.pop_back();
+ }
+ else
+ {
+ normalized_components.push_back(component);
+ }
+ }
+ return "/" + JoinStrings(normalized_components, "/");
}
WFSSRV::FileDescriptor* WFSSRV::FindFileDescriptor(u16 fd)
diff --git a/Source/Core/Core/IOS/WFS/WFSSRV.h b/Source/Core/Core/IOS/WFS/WFSSRV.h
index 86302a80bb..889bfc25fd 100644
--- a/Source/Core/Core/IOS/WFS/WFSSRV.h
+++ b/Source/Core/Core/IOS/WFS/WFSSRV.h
@@ -39,7 +39,7 @@ private:
std::string m_home_directory;
std::string m_current_directory;
- std::string ExpandPath(const std::string& path) const;
+ std::string NormalizePath(const std::string& path) const;
enum
{