summaryrefslogtreecommitdiffstats
path: root/sandbox/src
diff options
context:
space:
mode:
authorjschuh@chromium.org <jschuh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-13 20:21:04 +0000
committerjschuh@chromium.org <jschuh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-13 20:21:04 +0000
commitb0fa4c62d07643cf212eccb4152ad38cffa55c97 (patch)
treeb6befa3c19a658ad12f0e05d44b79a2c4dc82890 /sandbox/src
parenta88513546c84ee492c25cb502b0331dc9c5479a6 (diff)
downloadchromium_src-b0fa4c62d07643cf212eccb4152ad38cffa55c97.zip
chromium_src-b0fa4c62d07643cf212eccb4152ad38cffa55c97.tar.gz
chromium_src-b0fa4c62d07643cf212eccb4152ad38cffa55c97.tar.bz2
Had a bug in the handle table unit test. Added GetHandleName to fix the bug and make handle management easier.
TEST=sbox_unittests --gtest_filter=HandleTable.* Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=91270 Review URL: http://codereview.chromium.org/7218066 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@92403 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sandbox/src')
-rw-r--r--sandbox/src/handle_table.cc38
-rw-r--r--sandbox/src/handle_table.h4
-rw-r--r--sandbox/src/handle_table_unittest.cc4
3 files changed, 32 insertions, 14 deletions
diff --git a/sandbox/src/handle_table.cc b/sandbox/src/handle_table.cc
index c7fcf0a..90501a8 100644
--- a/sandbox/src/handle_table.cc
+++ b/sandbox/src/handle_table.cc
@@ -17,6 +17,8 @@ bool CompareHandleEntries(const SYSTEM_HANDLE_INFORMATION& a,
return a.ProcessId < b.ProcessId;
}
+static NtQueryObject QueryObject = NULL;
+
} // namespace
namespace sandbox {
@@ -84,7 +86,6 @@ HandleTable::HandleEntry::HandleEntry(
}
void HandleTable::HandleEntry::UpdateInfo(UpdateType flag) {
- static NtQueryObject QueryObject = NULL;
if (!QueryObject)
ResolveNTFunctionPtr("NtQueryObject", &QueryObject);
@@ -119,18 +120,8 @@ void HandleTable::HandleEntry::UpdateInfo(UpdateType flag) {
switch (flag) {
case UPDATE_INFO_AND_NAME:
if (type_info_buffer_.size() && handle_name_.empty()) {
- ULONG size = MAX_PATH;
- scoped_ptr<UNICODE_STRING> name;
- do {
- name.reset(reinterpret_cast<UNICODE_STRING*>(new BYTE[size]));
- result = QueryObject(reinterpret_cast<HANDLE>(
- handle_entry_->Handle), ObjectNameInformation, name.get(),
- size, &size);
- } while (result == STATUS_INFO_LENGTH_MISMATCH);
-
- if (NT_SUCCESS(result)) {
- handle_name_.assign(name->Buffer, name->Length / sizeof(wchar_t));
- }
+ GetHandleName(reinterpret_cast<HANDLE>(handle_entry_->Handle),
+ &handle_name_);
}
break;
@@ -144,6 +135,27 @@ void HandleTable::HandleEntry::UpdateInfo(UpdateType flag) {
}
}
+// Returns the object manager's name associated with a handle
+BOOL GetHandleName(HANDLE handle, string16* handle_name) {
+ if (!QueryObject)
+ ResolveNTFunctionPtr("NtQueryObject", &QueryObject);
+
+ ULONG size = MAX_PATH;
+ scoped_ptr<UNICODE_STRING> name;
+ NTSTATUS result;
+
+ do {
+ name.reset(reinterpret_cast<UNICODE_STRING*>(new BYTE[size]));
+ result = QueryObject(handle, ObjectNameInformation, name.get(),
+ size, &size);
+ } while (result == STATUS_INFO_LENGTH_MISMATCH);
+
+ if (NT_SUCCESS(result))
+ handle_name->assign(name->Buffer, name->Length / sizeof(wchar_t));
+
+ return NT_SUCCESS(result);
+}
+
const OBJECT_TYPE_INFORMATION* HandleTable::HandleEntry::TypeInfo() {
UpdateInfo(UPDATE_INFO_ONLY);
return type_info_buffer_.empty() ? NULL : type_info_internal();
diff --git a/sandbox/src/handle_table.h b/sandbox/src/handle_table.h
index 9b1fc66..4814aab 100644
--- a/sandbox/src/handle_table.h
+++ b/sandbox/src/handle_table.h
@@ -155,6 +155,10 @@ class HandleTable {
DISALLOW_COPY_AND_ASSIGN(HandleTable);
};
+// Returns the object manager's name associated with a handle
+BOOL GetHandleName(HANDLE handle, string16* handle_name);
+
+
} // namespace sandbox
#endif // SANDBOX_SRC_HANDLE_TABLE_H_
diff --git a/sandbox/src/handle_table_unittest.cc b/sandbox/src/handle_table_unittest.cc
index 696037f..3977c4a 100644
--- a/sandbox/src/handle_table_unittest.cc
+++ b/sandbox/src/handle_table_unittest.cc
@@ -47,6 +47,8 @@ TEST(HandleTable, FindHandle) {
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
OPEN_EXISTING, FILE_FLAG_DELETE_ON_CLOSE, NULL);
EXPECT_NE(INVALID_HANDLE_VALUE, file);
+ string16 handle_name;
+ ASSERT_NE(sandbox::GetHandleName(file, &handle_name), FALSE);
// Look for the handle in our process
bool handle_found = false;
@@ -54,7 +56,7 @@ TEST(HandleTable, FindHandle) {
for (HandleTable::Iterator it =
handles.HandlesForProcess(::GetCurrentProcessId());
it != handles.end(); ++it) {
- if (it->IsType(HandleTable::kTypeFile) && it->Name().compare(my_file)) {
+ if (it->IsType(HandleTable::kTypeFile) && it->Name() == handle_name) {
handle_found = true;
break;
}