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
@@ -508,6 +508,20 @@ TEST(SanitizeFilenameTest, VariousPatterns) {
|
||||
EXPECT_EQ("", httplib::sanitize_filename(" "));
|
||||
}
|
||||
|
||||
// On Windows a ':' ends a drive prefix or names an NTFS stream, so what comes
|
||||
// before it is dropped; anywhere else it is an ordinary file name character.
|
||||
TEST(SanitizeFilenameTest, ColonEndsPrefixOnlyOnWindows) {
|
||||
#ifdef _WIN32
|
||||
EXPECT_EQ("", httplib::sanitize_filename("C:.."));
|
||||
EXPECT_EQ("evil.dll", httplib::sanitize_filename("C:evil.dll"));
|
||||
EXPECT_EQ("stream", httplib::sanitize_filename("a.txt:stream"));
|
||||
#else
|
||||
EXPECT_EQ("C:..", httplib::sanitize_filename("C:.."));
|
||||
EXPECT_EQ("C:evil.dll", httplib::sanitize_filename("C:evil.dll"));
|
||||
EXPECT_EQ("a.txt:stream", httplib::sanitize_filename("a.txt:stream"));
|
||||
#endif
|
||||
}
|
||||
|
||||
// Forward declaration (see the base64_encode note below): split builds move the
|
||||
// definition into httplib.cc, so re-declaring it here lets the test link.
|
||||
namespace httplib {
|
||||
|
||||
Reference in new issue
Block a user