Commit 2c012cbb authored by rvargas@chromium.org's avatar rvargas@chromium.org

Net: make IsSafePortableRelativePath look for reserved names on all components.

Now a reserved name is not allowed on any component of the path.

BUG=none
test=net_unittests

R=asanka@chromium.org

Review URL: https://chromiumcodereview.appspot.com/23464037

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@221882 0039d316-1c4b-4281-b951-d872f2087c98
parent 595eec21
...@@ -1152,12 +1152,8 @@ bool IsSafePortablePathComponent(const base::FilePath& component) { ...@@ -1152,12 +1152,8 @@ bool IsSafePortablePathComponent(const base::FilePath& component) {
FilePathToString16(component, &component16) && FilePathToString16(component, &component16) &&
file_util::IsFilenameLegal(component16) && file_util::IsFilenameLegal(component16) &&
!IsShellIntegratedExtension(extension) && !IsShellIntegratedExtension(extension) &&
(sanitized == component.value()); (sanitized == component.value()) &&
} !IsReservedName(component.value());
bool IsSafePortableBasename(const base::FilePath& filename) {
return IsSafePortablePathComponent(filename) &&
!IsReservedName(filename.value());
} }
bool IsSafePortableRelativePath(const base::FilePath& path) { bool IsSafePortableRelativePath(const base::FilePath& path) {
...@@ -1171,7 +1167,7 @@ bool IsSafePortableRelativePath(const base::FilePath& path) { ...@@ -1171,7 +1167,7 @@ bool IsSafePortableRelativePath(const base::FilePath& path) {
if (!IsSafePortablePathComponent(base::FilePath(components[i]))) if (!IsSafePortablePathComponent(base::FilePath(components[i])))
return false; return false;
} }
return IsSafePortableBasename(path.BaseName()); return IsSafePortablePathComponent(path.BaseName());
} }
void GenerateSafeFileName(const std::string& mime_type, void GenerateSafeFileName(const std::string& mime_type,
......
...@@ -301,20 +301,17 @@ NET_EXPORT base::FilePath GenerateFileName( ...@@ -301,20 +301,17 @@ NET_EXPORT base::FilePath GenerateFileName(
const std::string& mime_type, const std::string& mime_type,
const std::string& default_name); const std::string& default_name);
// Valid basenames: // Valid components:
// * are not empty // * are not empty
// * are not Windows reserved names (CON, NUL.zip, etc.) // * are not Windows reserved names (CON, NUL.zip, etc.)
// * are just basenames
// * do not have trailing separators // * do not have trailing separators
// * do not equal kCurrentDirectory // * do not equal kCurrentDirectory
// * do not reference the parent directory // * do not reference the parent directory
// * are valid path components, which: // * do not contain illegal characters
// - * are not the empty string // * do not end with Windows shell-integrated extensions (even on posix)
// - * do not contain illegal characters // * do not begin with '.' (which would hide them in most file managers)
// - * do not end with Windows shell-integrated extensions (even on posix) // * do not end with ' ' or '.'
// - * do not begin with '.' (which would hide them in most file managers) NET_EXPORT bool IsSafePortablePathComponent(const base::FilePath& component);
// - * do not end with ' ' or '.'
NET_EXPORT bool IsSafePortableBasename(const base::FilePath& path);
// Basenames of valid relative paths are IsSafePortableBasename(), and internal // Basenames of valid relative paths are IsSafePortableBasename(), and internal
// path components of valid relative paths are valid path components as // path components of valid relative paths are valid path components as
......
...@@ -3458,17 +3458,17 @@ static const base::FilePath::CharType* kSafePortableRelativePaths[] = { ...@@ -3458,17 +3458,17 @@ static const base::FilePath::CharType* kSafePortableRelativePaths[] = {
#endif #endif
}; };
TEST(NetUtilTest, IsSafePortableBasename) { TEST(NetUtilTest, IsSafePortablePathComponent) {
for (size_t i = 0 ; i < arraysize(kSafePortableBasenames); ++i) { for (size_t i = 0 ; i < arraysize(kSafePortableBasenames); ++i) {
EXPECT_TRUE(IsSafePortableBasename(base::FilePath( EXPECT_TRUE(IsSafePortablePathComponent(base::FilePath(
kSafePortableBasenames[i]))) << kSafePortableBasenames[i]; kSafePortableBasenames[i]))) << kSafePortableBasenames[i];
} }
for (size_t i = 0 ; i < arraysize(kUnsafePortableBasenames); ++i) { for (size_t i = 0 ; i < arraysize(kUnsafePortableBasenames); ++i) {
EXPECT_FALSE(IsSafePortableBasename(base::FilePath( EXPECT_FALSE(IsSafePortablePathComponent(base::FilePath(
kUnsafePortableBasenames[i]))) << kUnsafePortableBasenames[i]; kUnsafePortableBasenames[i]))) << kUnsafePortableBasenames[i];
} }
for (size_t i = 0 ; i < arraysize(kSafePortableRelativePaths); ++i) { for (size_t i = 0 ; i < arraysize(kSafePortableRelativePaths); ++i) {
EXPECT_FALSE(IsSafePortableBasename(base::FilePath( EXPECT_FALSE(IsSafePortablePathComponent(base::FilePath(
kSafePortableRelativePaths[i]))) << kSafePortableRelativePaths[i]; kSafePortableRelativePaths[i]))) << kSafePortableRelativePaths[i];
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment