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

Side by Side Diff: sandbox/src/handle_table.cc

Issue 7292028: Revert 91270 - sbox_unittests HandleTable.FindTable failing on Win XP & Vista (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 5 months 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sandbox/src/handle_table.h ('k') | sandbox/src/handle_table_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "sandbox/src/handle_table.h" 5 #include "sandbox/src/handle_table.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cstdlib> 8 #include <cstdlib>
9 9
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "sandbox/src/win_utils.h" 11 #include "sandbox/src/win_utils.h"
12 12
13 namespace { 13 namespace {
14 14
15 bool CompareHandleEntries(const SYSTEM_HANDLE_INFORMATION& a, 15 bool CompareHandleEntries(const SYSTEM_HANDLE_INFORMATION& a,
16 const SYSTEM_HANDLE_INFORMATION& b) { 16 const SYSTEM_HANDLE_INFORMATION& b) {
17 return a.ProcessId < b.ProcessId; 17 return a.ProcessId < b.ProcessId;
18 } 18 }
19 19
20 static NtQueryObject QueryObject = NULL;
21
22 } // namespace 20 } // namespace
23 21
24 namespace sandbox { 22 namespace sandbox {
25 23
26 const char16* HandleTable::kTypeProcess = L"Process"; 24 const char16* HandleTable::kTypeProcess = L"Process";
27 const char16* HandleTable::kTypeThread = L"Thread"; 25 const char16* HandleTable::kTypeThread = L"Thread";
28 const char16* HandleTable::kTypeFile = L"File"; 26 const char16* HandleTable::kTypeFile = L"File";
29 const char16* HandleTable::kTypeDirectory = L"Directory"; 27 const char16* HandleTable::kTypeDirectory = L"Directory";
30 const char16* HandleTable::kTypeKey = L"Key"; 28 const char16* HandleTable::kTypeKey = L"Key";
31 const char16* HandleTable::kTypeWindowStation = L"WindowStation"; 29 const char16* HandleTable::kTypeWindowStation = L"WindowStation";
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 finish = std::upper_bound(start, finish, key, CompareHandleEntries); 77 finish = std::upper_bound(start, finish, key, CompareHandleEntries);
80 return Iterator(*this, start, finish); 78 return Iterator(*this, start, finish);
81 } 79 }
82 80
83 HandleTable::HandleEntry::HandleEntry( 81 HandleTable::HandleEntry::HandleEntry(
84 const SYSTEM_HANDLE_INFORMATION* handle_info_entry) 82 const SYSTEM_HANDLE_INFORMATION* handle_info_entry)
85 : handle_entry_(handle_info_entry), last_entry_(0) { 83 : handle_entry_(handle_info_entry), last_entry_(0) {
86 } 84 }
87 85
88 void HandleTable::HandleEntry::UpdateInfo(UpdateType flag) { 86 void HandleTable::HandleEntry::UpdateInfo(UpdateType flag) {
87 static NtQueryObject QueryObject = NULL;
89 if (!QueryObject) 88 if (!QueryObject)
90 ResolveNTFunctionPtr("NtQueryObject", &QueryObject); 89 ResolveNTFunctionPtr("NtQueryObject", &QueryObject);
91 90
92 NTSTATUS result; 91 NTSTATUS result;
93 92
94 // Always update the basic type info, but grab the names as needed. 93 // Always update the basic type info, but grab the names as needed.
95 if (needs_info_update()) { 94 if (needs_info_update()) {
96 handle_name_.clear(); 95 handle_name_.clear();
97 type_name_.clear(); 96 type_name_.clear();
98 last_entry_ = handle_entry_; 97 last_entry_ = handle_entry_;
(...skipping 14 matching lines...) Expand all
113 if (!NT_SUCCESS(result)) { 112 if (!NT_SUCCESS(result)) {
114 type_info_buffer_.clear(); 113 type_info_buffer_.clear();
115 return; 114 return;
116 } 115 }
117 } 116 }
118 117
119 // Don't bother copying out names until we ask for them, and then cache them. 118 // Don't bother copying out names until we ask for them, and then cache them.
120 switch (flag) { 119 switch (flag) {
121 case UPDATE_INFO_AND_NAME: 120 case UPDATE_INFO_AND_NAME:
122 if (type_info_buffer_.size() && handle_name_.empty()) { 121 if (type_info_buffer_.size() && handle_name_.empty()) {
123 GetHandleName(reinterpret_cast<HANDLE>(handle_entry_->Handle), 122 ULONG size = MAX_PATH;
124 &handle_name_); 123 scoped_ptr<UNICODE_STRING> name;
124 do {
125 name.reset(reinterpret_cast<UNICODE_STRING*>(new BYTE[size]));
126 result = QueryObject(reinterpret_cast<HANDLE>(
127 handle_entry_->Handle), ObjectNameInformation, name.get(),
128 size, &size);
129 } while (result == STATUS_INFO_LENGTH_MISMATCH);
130
131 if (NT_SUCCESS(result)) {
132 handle_name_.assign(name->Buffer, name->Length / sizeof(wchar_t));
133 }
125 } 134 }
126 break; 135 break;
127 136
128 case UPDATE_INFO_AND_TYPE_NAME: 137 case UPDATE_INFO_AND_TYPE_NAME:
129 if (!type_info_buffer_.empty() && type_info_internal()->Name.Buffer && 138 if (!type_info_buffer_.empty() && type_info_internal()->Name.Buffer &&
130 type_name_.empty()) { 139 type_name_.empty()) {
131 type_name_.assign(type_info_internal()->Name.Buffer, 140 type_name_.assign(type_info_internal()->Name.Buffer,
132 type_info_internal()->Name.Length / sizeof(wchar_t)); 141 type_info_internal()->Name.Length / sizeof(wchar_t));
133 } 142 }
134 break; 143 break;
135 } 144 }
136 } 145 }
137 146
138 // Returns the object manager's name associated with a handle
139 bool GetHandleName(HANDLE handle, string16* handle_name) {
140 if (!QueryObject)
141 ResolveNTFunctionPtr("NtQueryObject", &QueryObject);
142
143 ULONG size = MAX_PATH;
144 scoped_ptr<UNICODE_STRING> name;
145 NTSTATUS result;
146
147 do {
148 name.reset(reinterpret_cast<UNICODE_STRING*>(new BYTE[size]));
149 result = QueryObject(handle, ObjectNameInformation, name.get(),
150 size, &size);
151 } while (result == STATUS_INFO_LENGTH_MISMATCH);
152
153 if (NT_SUCCESS(result))
154 handle_name->assign(name->Buffer, name->Length / sizeof(wchar_t));
155
156 return NT_SUCCESS(result);
157 }
158
159 const OBJECT_TYPE_INFORMATION* HandleTable::HandleEntry::TypeInfo() { 147 const OBJECT_TYPE_INFORMATION* HandleTable::HandleEntry::TypeInfo() {
160 UpdateInfo(UPDATE_INFO_ONLY); 148 UpdateInfo(UPDATE_INFO_ONLY);
161 return type_info_buffer_.empty() ? NULL : type_info_internal(); 149 return type_info_buffer_.empty() ? NULL : type_info_internal();
162 } 150 }
163 151
164 const string16& HandleTable::HandleEntry::Name() { 152 const string16& HandleTable::HandleEntry::Name() {
165 UpdateInfo(UPDATE_INFO_AND_NAME); 153 UpdateInfo(UPDATE_INFO_AND_NAME);
166 return handle_name_; 154 return handle_name_;
167 } 155 }
168 156
(...skipping 15 matching lines...) Expand all
184 const SYSTEM_HANDLE_INFORMATION* start, 172 const SYSTEM_HANDLE_INFORMATION* start,
185 const SYSTEM_HANDLE_INFORMATION* end) 173 const SYSTEM_HANDLE_INFORMATION* end)
186 : table_(table), current_(start), end_(end) { 174 : table_(table), current_(start), end_(end) {
187 } 175 }
188 176
189 HandleTable::Iterator::Iterator(const Iterator& it) 177 HandleTable::Iterator::Iterator(const Iterator& it)
190 : table_(it.table_), current_(it.current_.handle_entry_), end_(it.end_) { 178 : table_(it.table_), current_(it.current_.handle_entry_), end_(it.end_) {
191 } 179 }
192 180
193 } // namespace sandbox 181 } // namespace sandbox
OLDNEW
« no previous file with comments | « sandbox/src/handle_table.h ('k') | sandbox/src/handle_table_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698