From 4d3f6a99781f7bdca5237c49fccdc6c796e6abcc Mon Sep 17 00:00:00 2001 From: "alexeypa@chromium.org" Date: Thu, 12 Jul 2012 22:39:33 +0000 Subject: Suppress STATUS_INVALID_HANDLE (0xc0000008) exceptions triggered by HandleCloserAgent. Dereferncing an invalid handle generates the STATUS_INVALID_HANDLE exception when handle tracing is enabled (by AppVerifier for example). HandleCloserAgent is expected to probe invalid handles, so this CL suppresses STATUS_INVALID_HANDLE exceptions triggered by HandleCloserAgent to make debugging easier. BUG=131699 Review URL: https://chromiumcodereview.appspot.com/10689081 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@146470 0039d316-1c4b-4281-b951-d872f2087c98 --- sandbox/src/handle_closer_agent.cc | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/sandbox/src/handle_closer_agent.cc b/sandbox/src/handle_closer_agent.cc index 78d060e..2b5ac97 100644 --- a/sandbox/src/handle_closer_agent.cc +++ b/sandbox/src/handle_closer_agent.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -8,6 +8,30 @@ #include "sandbox/src/nt_internals.h" #include "sandbox/src/win_utils.h" +namespace { + +// Returns type infomation for an NT object. This routine is expected to be +// called for invalid handles so it catches STATUS_INVALID_HANDLE exceptions +// that can be generated when handle tracing is enabled. +NTSTATUS QueryObjectTypeInformation(HANDLE handle, + void* buffer, + ULONG* size) { + static NtQueryObject QueryObject = NULL; + if (!QueryObject) + ResolveNTFunctionPtr("NtQueryObject", &QueryObject); + + NTSTATUS status = STATUS_UNSUCCESSFUL; + __try { + status = QueryObject(handle, ObjectTypeInformation, buffer, *size, size); + } __except(GetExceptionCode() == STATUS_INVALID_HANDLE ? + EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) { + status = STATUS_INVALID_HANDLE; + } + return status; +} + +} // namespace + namespace sandbox { // Memory buffer mapped from the parent, with the list of handles. @@ -59,10 +83,6 @@ bool HandleCloserAgent::CloseHandles() { if (!::GetProcessHandleCount(::GetCurrentProcess(), &handle_count)) return false; - static NtQueryObject QueryObject = NULL; - if (!QueryObject) - ResolveNTFunctionPtr("NtQueryObject", &QueryObject); - // Set up buffers for the type info and the name. std::vector type_info_buffer(sizeof(OBJECT_TYPE_INFORMATION) + 32 * sizeof(wchar_t)); @@ -81,13 +101,13 @@ bool HandleCloserAgent::CloseHandles() { // Get the type name, reusing the buffer. ULONG size = static_cast(type_info_buffer.size()); - rc = QueryObject(handle, ObjectTypeInformation, type_info, size, &size); + rc = QueryObjectTypeInformation(handle, type_info, &size); while (rc == STATUS_INFO_LENGTH_MISMATCH || rc == STATUS_BUFFER_OVERFLOW) { type_info_buffer.resize(size + sizeof(wchar_t)); type_info = reinterpret_cast( &(type_info_buffer[0])); - rc = QueryObject(handle, ObjectTypeInformation, type_info, size, &size); + rc = QueryObjectTypeInformation(handle, type_info, &size); // Leave padding for the nul terminator. if (NT_SUCCESS(0) && size == type_info_buffer.size()) rc = STATUS_INFO_LENGTH_MISMATCH; -- cgit v1.1