OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
6 #include <dirent.h> | 6 #include <dirent.h> |
7 | 7 |
8 extern "C" { | 8 extern "C" { |
9 #include <sandbox.h> | 9 #include <sandbox.h> |
10 } | 10 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 const char* escaped; | 54 const char* escaped; |
55 } string_escape_cases[] = { | 55 } string_escape_cases[] = { |
56 {"", ""}, | 56 {"", ""}, |
57 {"\b\f\n\r\t\\\"", "\\b\\f\\n\\r\\t\\\\\\\""}, | 57 {"\b\f\n\r\t\\\"", "\\b\\f\\n\\r\\t\\\\\\\""}, |
58 {"/'", "/'"}, | 58 {"/'", "/'"}, |
59 {"sandwich", "sandwich"}, | 59 {"sandwich", "sandwich"}, |
60 {"(sandwich)", "(sandwich)"}, | 60 {"(sandwich)", "(sandwich)"}, |
61 {"^\u2135.\u2136$", "^\\u2135.\\u2136$"}, | 61 {"^\u2135.\u2136$", "^\\u2135.\\u2136$"}, |
62 }; | 62 }; |
63 | 63 |
64 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(string_escape_cases); ++i) { | 64 for (size_t i = 0; i < arraysize(string_escape_cases); ++i) { |
65 std::string out; | 65 std::string out; |
66 std::string in(string_escape_cases[i].to_escape); | 66 std::string in(string_escape_cases[i].to_escape); |
67 EXPECT_TRUE(Sandbox::QuotePlainString(in, &out)); | 67 EXPECT_TRUE(Sandbox::QuotePlainString(in, &out)); |
68 EXPECT_EQ(string_escape_cases[i].escaped, out); | 68 EXPECT_EQ(string_escape_cases[i].escaped, out); |
69 } | 69 } |
70 } | 70 } |
71 | 71 |
72 TEST_F(MacDirAccessSandboxTest, RegexEscape) { | 72 TEST_F(MacDirAccessSandboxTest, RegexEscape) { |
73 const std::string kSandboxEscapeSuffix("(/|$)"); | 73 const std::string kSandboxEscapeSuffix("(/|$)"); |
74 const struct regex_test_data { | 74 const struct regex_test_data { |
(...skipping 21 matching lines...) Expand all Loading... |
96 { | 96 { |
97 std::string out; | 97 std::string out; |
98 EXPECT_TRUE(Sandbox::QuoteStringForRegex("}", &out)); // } == 0x7D == 125 | 98 EXPECT_TRUE(Sandbox::QuoteStringForRegex("}", &out)); // } == 0x7D == 125 |
99 EXPECT_FALSE(Sandbox::QuoteStringForRegex("~", &out)); // ~ == 0x7E == 126 | 99 EXPECT_FALSE(Sandbox::QuoteStringForRegex("~", &out)); // ~ == 0x7E == 126 |
100 EXPECT_FALSE( | 100 EXPECT_FALSE( |
101 Sandbox::QuoteStringForRegex(base::WideToUTF8(L"^\u2135.\u2136$"), | 101 Sandbox::QuoteStringForRegex(base::WideToUTF8(L"^\u2135.\u2136$"), |
102 &out)); | 102 &out)); |
103 } | 103 } |
104 | 104 |
105 { | 105 { |
106 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(regex_cases); ++i) { | 106 for (size_t i = 0; i < arraysize(regex_cases); ++i) { |
107 std::string out; | 107 std::string out; |
108 std::string in = base::WideToUTF8(regex_cases[i].to_escape); | 108 std::string in = base::WideToUTF8(regex_cases[i].to_escape); |
109 EXPECT_TRUE(Sandbox::QuoteStringForRegex(in, &out)); | 109 EXPECT_TRUE(Sandbox::QuoteStringForRegex(in, &out)); |
110 std::string expected("^"); | 110 std::string expected("^"); |
111 expected.append(regex_cases[i].escaped); | 111 expected.append(regex_cases[i].escaped); |
112 expected.append(kSandboxEscapeSuffix); | 112 expected.append(kSandboxEscapeSuffix); |
113 EXPECT_EQ(expected, out); | 113 EXPECT_EQ(expected, out); |
114 } | 114 } |
115 } | 115 } |
116 | 116 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 // /var which is a symlink to /private/var . | 152 // /var which is a symlink to /private/var . |
153 tmp_dir = Sandbox::GetCanonicalSandboxPath(tmp_dir); | 153 tmp_dir = Sandbox::GetCanonicalSandboxPath(tmp_dir); |
154 ScopedDirectory cleanup(&tmp_dir); | 154 ScopedDirectory cleanup(&tmp_dir); |
155 | 155 |
156 const char* sandbox_dir_cases[] = { | 156 const char* sandbox_dir_cases[] = { |
157 "simple_dir_name", | 157 "simple_dir_name", |
158 "^hello++ $", // Regex. | 158 "^hello++ $", // Regex. |
159 "\\^.$|()[]*+?{}", // All regex characters. | 159 "\\^.$|()[]*+?{}", // All regex characters. |
160 }; | 160 }; |
161 | 161 |
162 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(sandbox_dir_cases); ++i) { | 162 for (size_t i = 0; i < arraysize(sandbox_dir_cases); ++i) { |
163 const char* sandbox_dir_name = sandbox_dir_cases[i]; | 163 const char* sandbox_dir_name = sandbox_dir_cases[i]; |
164 base::FilePath sandbox_dir = tmp_dir.Append(sandbox_dir_name); | 164 base::FilePath sandbox_dir = tmp_dir.Append(sandbox_dir_name); |
165 ASSERT_TRUE(CreateDirectory(sandbox_dir)); | 165 ASSERT_TRUE(CreateDirectory(sandbox_dir)); |
166 ScopedDirectory cleanup_sandbox(&sandbox_dir); | 166 ScopedDirectory cleanup_sandbox(&sandbox_dir); |
167 | 167 |
168 // Create a sibling directory of the sandbox dir, whose name has sandbox dir | 168 // Create a sibling directory of the sandbox dir, whose name has sandbox dir |
169 // as a substring but to which access is denied. | 169 // as a substring but to which access is denied. |
170 std::string sibling_sandbox_dir_name_denied = | 170 std::string sibling_sandbox_dir_name_denied = |
171 std::string(sandbox_dir_cases[i]) + kDeniedSuffix; | 171 std::string(sandbox_dir_cases[i]) + kDeniedSuffix; |
172 base::FilePath sibling_sandbox_dir = tmp_dir.Append( | 172 base::FilePath sibling_sandbox_dir = tmp_dir.Append( |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 PLOG(ERROR) << "Sandbox breach: was able to write (" | 300 PLOG(ERROR) << "Sandbox breach: was able to write (" |
301 << denied_file2.value() | 301 << denied_file2.value() |
302 << ")"; | 302 << ")"; |
303 return -1; | 303 return -1; |
304 } | 304 } |
305 | 305 |
306 return 0; | 306 return 0; |
307 } | 307 } |
308 | 308 |
309 } // namespace content | 309 } // namespace content |
OLD | NEW |