summaryrefslogtreecommitdiffstats
path: root/sandbox/src
diff options
context:
space:
mode:
authorrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-21 18:54:19 +0000
committerrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-21 18:54:19 +0000
commit9342a65993056c500a2bedc9195b55da3938a2f7 (patch)
tree253da6026d7a39740fc53a140932f27c0ded0e3a /sandbox/src
parent6a6a790f78f858263a1295e11671c850b1094538 (diff)
downloadchromium_src-9342a65993056c500a2bedc9195b55da3938a2f7.zip
chromium_src-9342a65993056c500a2bedc9195b55da3938a2f7.tar.gz
chromium_src-9342a65993056c500a2bedc9195b55da3938a2f7.tar.bz2
Windows Sandbox: Perform case insensitive tests when checking
file handles to be returned to a sandboxed process. BUG=67215 TEST=sbox_unittests Review URL: http://codereview.chromium.org/5989004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@69847 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sandbox/src')
-rw-r--r--sandbox/src/win_utils.cc5
-rw-r--r--sandbox/src/win_utils_unittest.cc30
2 files changed, 32 insertions, 3 deletions
diff --git a/sandbox/src/win_utils.cc b/sandbox/src/win_utils.cc
index 85bf5f9..c1b4d2a 100644
--- a/sandbox/src/win_utils.cc
+++ b/sandbox/src/win_utils.cc
@@ -170,12 +170,11 @@ bool SameObject(HANDLE handle, const wchar_t* full_path) {
return false;
// Check up to the drive letter.
- if (0 != actual_path.compare(0, vol_length, vol_name))
+ if (0 != _wcsnicmp(actual_path.c_str(), vol_name, vol_length))
return false;
// Check the path after the drive letter.
- if (0 != actual_path.compare(vol_length, std::wstring::npos,
- &path[colon_pos + 1]))
+ if (0 != _wcsicmp(&actual_path[vol_length], &path[colon_pos + 1]))
return false;
return true;
diff --git a/sandbox/src/win_utils_unittest.cc b/sandbox/src/win_utils_unittest.cc
index 3afa78d..99ce7e2 100644
--- a/sandbox/src/win_utils_unittest.cc
+++ b/sandbox/src/win_utils_unittest.cc
@@ -4,6 +4,7 @@
#include <windows.h>
+#include "base/scoped_handle_win.h"
#include "sandbox/src/win_utils.h"
#include "sandbox/tests/common/test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -49,3 +50,32 @@ TEST(WinUtils, IsReparsePoint) {
EXPECT_TRUE(::CloseHandle(dir));
EXPECT_TRUE(::RemoveDirectory(my_folder));
}
+
+TEST(WinUtils, SameObject) {
+ using sandbox::SameObject;
+
+ // Create a temp file because we need write access to it.
+ wchar_t temp_directory[MAX_PATH];
+ wchar_t my_folder[MAX_PATH];
+ ASSERT_NE(::GetTempPath(MAX_PATH, temp_directory), 0u);
+ ASSERT_NE(::GetTempFileName(temp_directory, L"test", 0, my_folder), 0u);
+
+ // Delete the file and create a directory instead.
+ ASSERT_TRUE(::DeleteFile(my_folder));
+ ASSERT_TRUE(::CreateDirectory(my_folder, NULL));
+
+ std::wstring folder(my_folder);
+ std::wstring file_name = folder + L"\\foo.txt";
+ const ULONG kSharing = FILE_SHARE_WRITE | FILE_SHARE_READ | FILE_SHARE_DELETE;
+ ScopedHandle file(CreateFile(file_name.c_str(), GENERIC_WRITE, kSharing, NULL,
+ CREATE_ALWAYS, FILE_FLAG_DELETE_ON_CLOSE, NULL));
+
+ EXPECT_TRUE(file.IsValid());
+ std::wstring file_name_nt1 = std::wstring(L"\\??\\") + file_name;
+ std::wstring file_name_nt2 = std::wstring(L"\\??\\") + folder + L"\\FOO.txT";
+ EXPECT_TRUE(SameObject(file.Get(), file_name_nt1.c_str()));
+ EXPECT_TRUE(SameObject(file.Get(), file_name_nt2.c_str()));
+
+ file.Close();
+ EXPECT_TRUE(::RemoveDirectory(my_folder));
+}