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

Unified Diff: sandbox/win/src/sandbox_nt_util.cc

Issue 700373005: Check within target process for policy match on registry intercepts (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits. fix dcheck Created 6 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sandbox/win/src/sandbox_nt_util.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..cc446e59ab0ca91c2041b95e292b50177d63801a 100644
--- a/sandbox/win/src/sandbox_nt_util.cc
+++ b/sandbox/win/src/sandbox_nt_util.cc
@@ -215,6 +215,78 @@ 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(path);
+ *full_path = NULL;
+ OBJECT_NAME_INFORMATION* handle_name = NULL;
+ NTSTATUS ret = STATUS_UNSUCCESSFUL;
+ __try {
+ do {
+ static NtQueryObjectFunction NtQueryObject = NULL;
+ if (!NtQueryObject)
+ 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,
« no previous file with comments | « sandbox/win/src/sandbox_nt_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698