Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(127)

Side by Side Diff: sandbox/win/src/process_policy_test.cc

Issue 382613002: Fixes for re-enabling more MSVC level 4 warnings: sandbox/ edition (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #include <memory> 5 #include <memory>
6 #include <string> 6 #include <string>
7 7
8 #include "base/strings/string16.h" 8 #include "base/strings/string16.h"
9 #include "base/strings/sys_string_conversions.h" 9 #include "base/strings/sys_string_conversions.h"
10 #include "base/win/scoped_handle.h" 10 #include "base/win/scoped_handle.h"
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 if (argc != 1) { 147 if (argc != 1) {
148 return SBOX_TEST_FAILED_TO_EXECUTE_COMMAND; 148 return SBOX_TEST_FAILED_TO_EXECUTE_COMMAND;
149 } 149 }
150 if ((NULL == argv) || (NULL == argv[0])) { 150 if ((NULL == argv) || (NULL == argv[0])) {
151 return SBOX_TEST_FAILED_TO_EXECUTE_COMMAND; 151 return SBOX_TEST_FAILED_TO_EXECUTE_COMMAND;
152 } 152 }
153 153
154 // TEST 4: Try file name in the app_name and current directory sets correctly. 154 // TEST 4: Try file name in the app_name and current directory sets correctly.
155 base::string16 system32 = MakeFullPathToSystem32(L""); 155 base::string16 system32 = MakeFullPathToSystem32(L"");
156 wchar_t current_directory[MAX_PATH + 1]; 156 wchar_t current_directory[MAX_PATH + 1];
157 int result4;
158 bool test_succeeded = false;
159 DWORD ret = ::GetCurrentDirectory(MAX_PATH, current_directory); 157 DWORD ret = ::GetCurrentDirectory(MAX_PATH, current_directory);
160 if (!ret) 158 if (!ret)
161 return SBOX_TEST_FIRST_ERROR; 159 return SBOX_TEST_FIRST_ERROR;
160 if (ret >= MAX_PATH)
161 return SBOX_TEST_FAILED;
162 162
163 if (ret < MAX_PATH) { 163 current_directory[ret] = L'\\';
164 current_directory[ret] = L'\\'; 164 current_directory[ret+1] = L'\0';
165 current_directory[ret+1] = L'\0'; 165 if (!::SetCurrentDirectory(system32.c_str()))
cpu_(ooo_6.6-7.5) 2014/07/10 00:49:34 you are using the nice no brackets style for if()
Peter Kasting 2014/07/10 01:19:31 Good catch, I didn't look hard enough.
166 if (::SetCurrentDirectory(system32.c_str())) { 166 return SBOX_TEST_SECOND_ERROR;
167 result4 = CreateProcessHelper(argv[0], base::string16());
168 if (::SetCurrentDirectory(current_directory)) {
169 test_succeeded = true;
170 }
171 } else {
172 return SBOX_TEST_SECOND_ERROR;
173 }
174 }
175 if (!test_succeeded)
176 result4 = SBOX_TEST_FAILED;
177 167
178 return result4; 168 const int result4 = CreateProcessHelper(argv[0], base::string16());
169 return ::SetCurrentDirectory(current_directory) ? result4 : SBOX_TEST_FAILED;
179 } 170 }
180 171
181 SBOX_TESTS_COMMAND int Process_RunApp5(int argc, wchar_t **argv) { 172 SBOX_TESTS_COMMAND int Process_RunApp5(int argc, wchar_t **argv) {
182 if (argc != 1) { 173 if (argc != 1) {
183 return SBOX_TEST_FAILED_TO_EXECUTE_COMMAND; 174 return SBOX_TEST_FAILED_TO_EXECUTE_COMMAND;
184 } 175 }
185 if ((NULL == argv) || (NULL == argv[0])) { 176 if ((NULL == argv) || (NULL == argv[0])) {
186 return SBOX_TEST_FAILED_TO_EXECUTE_COMMAND; 177 return SBOX_TEST_FAILED_TO_EXECUTE_COMMAND;
187 } 178 }
188 base::string16 path = MakeFullPathToSystem32(argv[0]); 179 base::string16 path = MakeFullPathToSystem32(argv[0]);
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 ASSERT_TRUE(!exe_path.empty()); 370 ASSERT_TRUE(!exe_path.empty());
380 EXPECT_TRUE(runner.AddRule(TargetPolicy::SUBSYS_PROCESS, 371 EXPECT_TRUE(runner.AddRule(TargetPolicy::SUBSYS_PROCESS,
381 TargetPolicy::PROCESS_ALL_EXEC, 372 TargetPolicy::PROCESS_ALL_EXEC,
382 exe_path.c_str())); 373 exe_path.c_str()));
383 374
384 EXPECT_EQ(SBOX_TEST_SUCCEEDED, 375 EXPECT_EQ(SBOX_TEST_SUCCEEDED,
385 runner.RunTest(L"Process_GetChildProcessToken findstr.exe")); 376 runner.RunTest(L"Process_GetChildProcessToken findstr.exe"));
386 } 377 }
387 378
388 } // namespace sandbox 379 } // namespace sandbox
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698