Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/win_utils.h" | 5 #include "sandbox/win/src/win_utils.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/logging.h" | |
| 10 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 11 #include "sandbox/win/src/internal_types.h" | 10 #include "sandbox/win/src/internal_types.h" |
| 12 #include "sandbox/win/src/nt_internals.h" | 11 #include "sandbox/win/src/nt_internals.h" |
| 12 #include "sandbox/win/src/sandbox_nt_util.h" | |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 // Holds the information about a known registry key. | 16 // Holds the information about a known registry key. |
| 17 struct KnownReservedKey { | 17 struct KnownReservedKey { |
| 18 const wchar_t* name; | 18 const wchar_t* name; |
| 19 HKEY key; | 19 HKEY key; |
| 20 }; | 20 }; |
| 21 | 21 |
| 22 // Contains all the known registry key by name and by handle. | 22 // Contains all the known registry key by name and by handle. |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 97 do { | 97 do { |
| 98 path = path.substr(0, last_pos); | 98 path = path.substr(0, last_pos); |
| 99 | 99 |
| 100 DWORD attributes = ::GetFileAttributes(path.c_str()); | 100 DWORD attributes = ::GetFileAttributes(path.c_str()); |
| 101 if (INVALID_FILE_ATTRIBUTES == attributes) { | 101 if (INVALID_FILE_ATTRIBUTES == attributes) { |
| 102 DWORD error = ::GetLastError(); | 102 DWORD error = ::GetLastError(); |
| 103 if (error != ERROR_FILE_NOT_FOUND && | 103 if (error != ERROR_FILE_NOT_FOUND && |
| 104 error != ERROR_PATH_NOT_FOUND && | 104 error != ERROR_PATH_NOT_FOUND && |
| 105 error != ERROR_INVALID_NAME) { | 105 error != ERROR_INVALID_NAME) { |
| 106 // Unexpected error. | 106 // Unexpected error. |
| 107 NOTREACHED(); | 107 NOTREACHED_NT(); |
| 108 return error; | 108 return error; |
| 109 } | 109 } |
| 110 } else if (FILE_ATTRIBUTE_REPARSE_POINT & attributes) { | 110 } else if (FILE_ATTRIBUTE_REPARSE_POINT & attributes) { |
| 111 // This is a reparse point. | 111 // This is a reparse point. |
| 112 *result = true; | 112 *result = true; |
| 113 return ERROR_SUCCESS; | 113 return ERROR_SUCCESS; |
| 114 } | 114 } |
| 115 | 115 |
| 116 last_pos = path.rfind(L'\\'); | 116 last_pos = path.rfind(L'\\'); |
| 117 } while (last_pos != std::wstring::npos); | 117 } while (last_pos != std::wstring::npos); |
| 118 | 118 |
| 119 *result = false; | 119 *result = false; |
| 120 return ERROR_SUCCESS; | 120 return ERROR_SUCCESS; |
| 121 } | 121 } |
| 122 | 122 |
| 123 // We get a |full_path| of the form \??\c:\some\foo\bar, and the name that | 123 // We get a |full_path| of the form \??\c:\some\foo\bar, and the name that |
| 124 // we'll get from |handle| will be \device\harddiskvolume1\some\foo\bar. | 124 // we'll get from |handle| will be \device\harddiskvolume1\some\foo\bar. |
| 125 bool SameObject(HANDLE handle, const wchar_t* full_path) { | 125 bool SameObject(HANDLE handle, const wchar_t* full_path) { |
| 126 std::wstring path(full_path); | 126 std::wstring path(full_path); |
| 127 DCHECK(!path.empty()); | 127 DCHECK_NT(!path.empty()); |
| 128 | 128 |
| 129 // Check if it's a pipe. | 129 // Check if it's a pipe. |
| 130 if (IsPipe(path)) | 130 if (IsPipe(path)) |
| 131 return true; | 131 return true; |
| 132 | 132 |
| 133 std::wstring actual_path; | 133 std::wstring actual_path; |
| 134 if (!GetPathFromHandle(handle, &actual_path)) | 134 if (!GetPathFromHandle(handle, &actual_path)) |
| 135 return false; | 135 return false; |
| 136 | 136 |
| 137 // This may end with a backslash. | 137 // This may end with a backslash. |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 312 FARPROC* function_ptr = reinterpret_cast<FARPROC*>(ptr); | 312 FARPROC* function_ptr = reinterpret_cast<FARPROC*>(ptr); |
| 313 *function_ptr = ::GetProcAddress(ntdll, name); | 313 *function_ptr = ::GetProcAddress(ntdll, name); |
| 314 | 314 |
| 315 for (int tries = 1; !(*function_ptr) && tries < max_tries; ++tries) { | 315 for (int tries = 1; !(*function_ptr) && tries < max_tries; ++tries) { |
| 316 if (tries >= sleep_threshold) | 316 if (tries >= sleep_threshold) |
| 317 ::Sleep(1); | 317 ::Sleep(1); |
| 318 ntdll = ::GetModuleHandle(sandbox::kNtdllName); | 318 ntdll = ::GetModuleHandle(sandbox::kNtdllName); |
| 319 *function_ptr = ::GetProcAddress(ntdll, name); | 319 *function_ptr = ::GetProcAddress(ntdll, name); |
| 320 } | 320 } |
| 321 | 321 |
| 322 CHECK(*function_ptr); | 322 VERIFY(*function_ptr); |
|
rvargas (doing something else)
2013/11/27 23:53:51
We need CHECK_NT
robertshield
2013/11/29 01:21:26
Done.
| |
| 323 } | 323 } |
| OLD | NEW |