Revert 91270 - sbox_unittests HandleTable.FindTable failing on Win XP & Vista
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.* Review URL: http://codereview.chromium.org/7218066 TBR=jschuh@chromium.org Review URL: http://codereview.chromium.org/7292028 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@91271 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
@@ -17,8 +17,6 @@ bool CompareHandleEntries(const SYSTEM_HANDLE_INFORMATION& a,
|
|||||||
return a.ProcessId < b.ProcessId;
|
return a.ProcessId < b.ProcessId;
|
||||||
}
|
}
|
||||||
|
|
||||||
static NtQueryObject QueryObject = NULL;
|
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
namespace sandbox {
|
namespace sandbox {
|
||||||
@@ -86,6 +84,7 @@ HandleTable::HandleEntry::HandleEntry(
|
|||||||
}
|
}
|
||||||
|
|
||||||
void HandleTable::HandleEntry::UpdateInfo(UpdateType flag) {
|
void HandleTable::HandleEntry::UpdateInfo(UpdateType flag) {
|
||||||
|
static NtQueryObject QueryObject = NULL;
|
||||||
if (!QueryObject)
|
if (!QueryObject)
|
||||||
ResolveNTFunctionPtr("NtQueryObject", &QueryObject);
|
ResolveNTFunctionPtr("NtQueryObject", &QueryObject);
|
||||||
|
|
||||||
@@ -120,8 +119,18 @@ void HandleTable::HandleEntry::UpdateInfo(UpdateType flag) {
|
|||||||
switch (flag) {
|
switch (flag) {
|
||||||
case UPDATE_INFO_AND_NAME:
|
case UPDATE_INFO_AND_NAME:
|
||||||
if (type_info_buffer_.size() && handle_name_.empty()) {
|
if (type_info_buffer_.size() && handle_name_.empty()) {
|
||||||
GetHandleName(reinterpret_cast<HANDLE>(handle_entry_->Handle),
|
ULONG size = MAX_PATH;
|
||||||
&handle_name_);
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -135,27 +144,6 @@ 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() {
|
const OBJECT_TYPE_INFORMATION* HandleTable::HandleEntry::TypeInfo() {
|
||||||
UpdateInfo(UPDATE_INFO_ONLY);
|
UpdateInfo(UPDATE_INFO_ONLY);
|
||||||
return type_info_buffer_.empty() ? NULL : type_info_internal();
|
return type_info_buffer_.empty() ? NULL : type_info_internal();
|
||||||
|
@@ -155,10 +155,6 @@ class HandleTable {
|
|||||||
DISALLOW_COPY_AND_ASSIGN(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
|
} // namespace sandbox
|
||||||
|
|
||||||
#endif // SANDBOX_SRC_HANDLE_TABLE_H_
|
#endif // SANDBOX_SRC_HANDLE_TABLE_H_
|
||||||
|
@@ -47,8 +47,6 @@ TEST(HandleTable, FindHandle) {
|
|||||||
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
|
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
|
||||||
OPEN_EXISTING, FILE_FLAG_DELETE_ON_CLOSE, NULL);
|
OPEN_EXISTING, FILE_FLAG_DELETE_ON_CLOSE, NULL);
|
||||||
EXPECT_NE(INVALID_HANDLE_VALUE, file);
|
EXPECT_NE(INVALID_HANDLE_VALUE, file);
|
||||||
string16 handle_name;
|
|
||||||
ASSERT_EQ(sandbox::GetHandleName(file, &handle_name), true);
|
|
||||||
|
|
||||||
// Look for the handle in our process
|
// Look for the handle in our process
|
||||||
bool handle_found = false;
|
bool handle_found = false;
|
||||||
@@ -56,7 +54,7 @@ TEST(HandleTable, FindHandle) {
|
|||||||
for (HandleTable::Iterator it =
|
for (HandleTable::Iterator it =
|
||||||
handles.HandlesForProcess(::GetCurrentProcessId());
|
handles.HandlesForProcess(::GetCurrentProcessId());
|
||||||
it != handles.end(); ++it) {
|
it != handles.end(); ++it) {
|
||||||
if (it->IsType(HandleTable::kTypeFile) && it->Name() == handle_name) {
|
if (it->IsType(HandleTable::kTypeFile) && it->Name().compare(my_file)) {
|
||||||
handle_found = true;
|
handle_found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user