mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2026-10-28 12:40:54 +00:00
Treat ':' as a path separator in sanitize_filename on Windows (#2651)
On Windows a ':' ends a drive prefix or starts an NTFS stream name, so a filename such as "C:.." or "a.txt:stream" survived sanitize_filename and could replace the upload directory or write to an alternate data stream. Cut at ':' on Windows as well.
This commit is contained in:
1 parent
252dbaa505
commit
578e4815b7
3 files changed
+21
-2
No files matched your search
@@ -11975,8 +11975,13 @@ inline std::string decode_query_component(const std::string &component,
|
||||
}
|
||||
|
||||
inline std::string sanitize_filename(const std::string &filename) {
|
||||
// Extract basename: find the last path separator (/ or \)
|
||||
// Extract basename: find the last path separator (/ or \) and, on Windows,
|
||||
// ':', which ends a drive prefix ("C:..") or names an NTFS stream ("a:b")
|
||||
#ifdef _WIN32
|
||||
auto pos = filename.find_last_of("/\\:");
|
||||
#else
|
||||
auto pos = filename.find_last_of("/\\");
|
||||
#endif
|
||||
auto result =
|
||||
(pos != std::string::npos) ? filename.substr(pos + 1) : filename;
|
||||
|
||||
|
||||
Reference in new issue
Block a user