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

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

Issue 109843003: Replace wstring with string16 in sandbox (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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
« no previous file with comments | « sandbox/win/src/process_thread_dispatcher.h ('k') | sandbox/win/src/process_thread_policy.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "sandbox/win/src/process_thread_dispatcher.h" 5 #include "sandbox/win/src/process_thread_dispatcher.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "sandbox/win/src/crosscall_client.h" 9 #include "sandbox/win/src/crosscall_client.h"
10 #include "sandbox/win/src/interception.h" 10 #include "sandbox/win/src/interception.h"
(...skipping 11 matching lines...) Expand all
22 // 22 //
23 // The application name is the first element of the command line. If 23 // The application name is the first element of the command line. If
24 // there is no quotes, the first element is delimited by the first space. 24 // there is no quotes, the first element is delimited by the first space.
25 // If there are quotes, the first element is delimited by the quotes. 25 // If there are quotes, the first element is delimited by the quotes.
26 // 26 //
27 // The create process call is smarter than us. It tries really hard to launch 27 // The create process call is smarter than us. It tries really hard to launch
28 // the process even if the command line is wrong. For example: 28 // the process even if the command line is wrong. For example:
29 // "c:\program files\test param" will first try to launch c:\program.exe then 29 // "c:\program files\test param" will first try to launch c:\program.exe then
30 // c:\program files\test.exe. We don't do that, we stop after at the first 30 // c:\program files\test.exe. We don't do that, we stop after at the first
31 // space when there is no quotes. 31 // space when there is no quotes.
32 std::wstring GetPathFromCmdLine(const std::wstring &cmd_line) { 32 base::string16 GetPathFromCmdLine(const base::string16 &cmd_line) {
33 std::wstring exe_name; 33 base::string16 exe_name;
34 // Check if it starts with '"'. 34 // Check if it starts with '"'.
35 if (cmd_line[0] == L'\"') { 35 if (cmd_line[0] == L'\"') {
36 // Find the position of the second '"', this terminates the path. 36 // Find the position of the second '"', this terminates the path.
37 std::wstring::size_type pos = cmd_line.find(L'\"', 1); 37 base::string16::size_type pos = cmd_line.find(L'\"', 1);
38 if (std::wstring::npos == pos) 38 if (base::string16::npos == pos)
39 return cmd_line; 39 return cmd_line;
40 exe_name = cmd_line.substr(1, pos - 1); 40 exe_name = cmd_line.substr(1, pos - 1);
41 } else { 41 } else {
42 // There is no '"', that means that the appname is terminated at the 42 // There is no '"', that means that the appname is terminated at the
43 // first space. 43 // first space.
44 std::wstring::size_type pos = cmd_line.find(L' '); 44 base::string16::size_type pos = cmd_line.find(L' ');
45 if (std::wstring::npos == pos) { 45 if (base::string16::npos == pos) {
46 // There is no space, the cmd_line contains only the app_name 46 // There is no space, the cmd_line contains only the app_name
47 exe_name = cmd_line; 47 exe_name = cmd_line;
48 } else { 48 } else {
49 exe_name = cmd_line.substr(0, pos); 49 exe_name = cmd_line.substr(0, pos);
50 } 50 }
51 } 51 }
52 52
53 return exe_name; 53 return exe_name;
54 } 54 }
55 55
56 // Returns true is the path in parameter is relative. False if it's 56 // Returns true is the path in parameter is relative. False if it's
57 // absolute. 57 // absolute.
58 bool IsPathRelative(const std::wstring &path) { 58 bool IsPathRelative(const base::string16 &path) {
59 // A path is Relative if it's not a UNC path beginnning with \\ or a 59 // A path is Relative if it's not a UNC path beginnning with \\ or a
60 // path beginning with a drive. (i.e. X:\) 60 // path beginning with a drive. (i.e. X:\)
61 if (path.find(L"\\\\") == 0 || path.find(L":\\") == 1) 61 if (path.find(L"\\\\") == 0 || path.find(L":\\") == 1)
62 return false; 62 return false;
63 return true; 63 return true;
64 } 64 }
65 65
66 // Converts a relative path to an absolute path. 66 // Converts a relative path to an absolute path.
67 bool ConvertToAbsolutePath(const std::wstring& child_current_directory, 67 bool ConvertToAbsolutePath(const base::string16& child_current_directory,
68 bool use_env_path, std::wstring *path) { 68 bool use_env_path, base::string16 *path) {
69 wchar_t file_buffer[MAX_PATH]; 69 wchar_t file_buffer[MAX_PATH];
70 wchar_t *file_part = NULL; 70 wchar_t *file_part = NULL;
71 71
72 // Here we should start by looking at the path where the child application was 72 // Here we should start by looking at the path where the child application was
73 // started. We don't have this information yet. 73 // started. We don't have this information yet.
74 DWORD result = 0; 74 DWORD result = 0;
75 if (use_env_path) { 75 if (use_env_path) {
76 // Try with the complete path 76 // Try with the complete path
77 result = ::SearchPath(NULL, path->c_str(), NULL, MAX_PATH, file_buffer, 77 result = ::SearchPath(NULL, path->c_str(), NULL, MAX_PATH, file_buffer,
78 &file_part); 78 &file_part);
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 HANDLE handle; 194 HANDLE handle;
195 NTSTATUS ret = ProcessPolicy::OpenProcessTokenExAction(*ipc->client_info, 195 NTSTATUS ret = ProcessPolicy::OpenProcessTokenExAction(*ipc->client_info,
196 process, 196 process,
197 desired_access, 197 desired_access,
198 attributes, &handle); 198 attributes, &handle);
199 ipc->return_info.nt_status = ret; 199 ipc->return_info.nt_status = ret;
200 ipc->return_info.handle = handle; 200 ipc->return_info.handle = handle;
201 return true; 201 return true;
202 } 202 }
203 203
204 bool ThreadProcessDispatcher::CreateProcessW(IPCInfo* ipc, std::wstring* name, 204 bool ThreadProcessDispatcher::CreateProcessW(IPCInfo* ipc, base::string16* name,
205 std::wstring* cmd_line, 205 base::string16* cmd_line,
206 std::wstring* cur_dir, 206 base::string16* cur_dir,
207 CountedBuffer* info) { 207 CountedBuffer* info) {
208 if (sizeof(PROCESS_INFORMATION) != info->Size()) 208 if (sizeof(PROCESS_INFORMATION) != info->Size())
209 return false; 209 return false;
210 210
211 // Check if there is an application name. 211 // Check if there is an application name.
212 std::wstring exe_name; 212 base::string16 exe_name;
213 if (!name->empty()) 213 if (!name->empty())
214 exe_name = *name; 214 exe_name = *name;
215 else 215 else
216 exe_name = GetPathFromCmdLine(*cmd_line); 216 exe_name = GetPathFromCmdLine(*cmd_line);
217 217
218 if (IsPathRelative(exe_name)) { 218 if (IsPathRelative(exe_name)) {
219 if (!ConvertToAbsolutePath(*cur_dir, name->empty(), &exe_name)) { 219 if (!ConvertToAbsolutePath(*cur_dir, name->empty(), &exe_name)) {
220 // Cannot find the path. Maybe the file does not exist. 220 // Cannot find the path. Maybe the file does not exist.
221 ipc->return_info.win32_result = ERROR_FILE_NOT_FOUND; 221 ipc->return_info.win32_result = ERROR_FILE_NOT_FOUND;
222 return true; 222 return true;
(...skipping 13 matching lines...) Expand all
236 // If our logic was wrong, at least we wont allow create a random process. 236 // If our logic was wrong, at least we wont allow create a random process.
237 DWORD ret = ProcessPolicy::CreateProcessWAction(eval, *ipc->client_info, 237 DWORD ret = ProcessPolicy::CreateProcessWAction(eval, *ipc->client_info,
238 exe_name, *cmd_line, 238 exe_name, *cmd_line,
239 proc_info); 239 proc_info);
240 240
241 ipc->return_info.win32_result = ret; 241 ipc->return_info.win32_result = ret;
242 return true; 242 return true;
243 } 243 }
244 244
245 } // namespace sandbox 245 } // namespace sandbox
OLDNEW
« no previous file with comments | « sandbox/win/src/process_thread_dispatcher.h ('k') | sandbox/win/src/process_thread_policy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698