Chromium Code Reviews| Index: sandbox/win/src/sandbox_nt_util.cc |
| diff --git a/sandbox/win/src/sandbox_nt_util.cc b/sandbox/win/src/sandbox_nt_util.cc |
| index 12dd7d8c88c72b561b6ba814b789e3d217ded5c1..a0f84b7a01101ada7157fb681f4b80b4b3eeb6bb 100644 |
| --- a/sandbox/win/src/sandbox_nt_util.cc |
| +++ b/sandbox/win/src/sandbox_nt_util.cc |
| @@ -215,6 +215,77 @@ NTSTATUS CopyData(void* destination, const void* source, size_t bytes) { |
| return ret; |
| } |
| +NTSTATUS AllocAndGetFullPath(HANDLE root, |
| + wchar_t* path, |
| + wchar_t** full_path) { |
| + if (!InitHeap()) |
| + return STATUS_NO_MEMORY; |
| + |
| + DCHECK_NT(full_path); |
| + DCHECK_NT(key_name); |
| + *full_path = NULL; |
| + OBJECT_NAME_INFORMATION* handle_name = NULL; |
| + NTSTATUS ret = STATUS_UNSUCCESSFUL; |
| + __try { |
| + do { |
| + NtQueryObjectFunction NtQueryObject = NULL; |
|
jschuh
2014/11/11 22:16:06
I think it's safe to make this static, and just ch
Will Harris
2014/11/12 00:30:37
Done.
|
| + ResolveNTFunctionPtr("NtQueryObject", &NtQueryObject); |
| + |
| + ULONG size = 0; |
| + // Query the name information a first time to get the size of the name. |
| + ret = NtQueryObject(root, ObjectNameInformation, NULL, 0, &size); |
| + |
| + if (size) { |
| + handle_name = reinterpret_cast<OBJECT_NAME_INFORMATION*>( |
| + new(NT_ALLOC) BYTE[size]); |
| + |
| + // Query the name information a second time to get the name of the |
| + // object referenced by the handle. |
| + ret = NtQueryObject(root, ObjectNameInformation, handle_name, size, |
| + &size); |
| + } |
| + |
| + if (STATUS_SUCCESS != ret) |
| + break; |
| + |
| + // Space for path + '\' + name + '\0'. |
| + size_t name_length = handle_name->ObjectName.Length + |
| + (wcslen(path) + 2) * sizeof(wchar_t); |
| + *full_path = new(NT_ALLOC) wchar_t[name_length/sizeof(wchar_t)]; |
| + if (NULL == *full_path) |
| + break; |
| + wchar_t* off = *full_path; |
| + ret = CopyData(off, handle_name->ObjectName.Buffer, |
| + handle_name->ObjectName.Length); |
| + if (!NT_SUCCESS(ret)) |
| + break; |
| + off += handle_name->ObjectName.Length / sizeof(wchar_t); |
| + *off = L'\\'; |
| + off += 1; |
| + ret = CopyData(off, path, wcslen(path) * sizeof(wchar_t)); |
| + if (!NT_SUCCESS(ret)) |
| + break; |
| + off += wcslen(path); |
| + *off = L'\0'; |
| + } while (false); |
| + } __except(EXCEPTION_EXECUTE_HANDLER) { |
| + ret = GetExceptionCode(); |
| + } |
| + |
| + if (!NT_SUCCESS(ret)) { |
| + if (*full_path) { |
| + operator delete(*full_path, NT_ALLOC); |
| + *full_path = NULL; |
| + } |
| + if (handle_name) { |
| + operator delete(handle_name, NT_ALLOC); |
| + handle_name = NULL; |
| + } |
| + } |
| + |
| + return ret; |
| +} |
| + |
| // Hacky code... replace with AllocAndCopyObjectAttributes. |
| NTSTATUS AllocAndCopyName(const OBJECT_ATTRIBUTES* in_object, |
| wchar_t** out_name, uint32* attributes, |