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

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

Issue 378030: 64-bit compatibility changes for the sandbox code (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sandbox/src/sandbox_nt_util.h ('k') | sandbox/src/service_resolver.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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/sandbox_nt_util.h" 5 #include "sandbox/src/sandbox_nt_util.h"
6 6
7 #include "base/pe_image.h" 7 #include "base/pe_image.h"
8 #include "sandbox/src/sandbox_factory.h" 8 #include "sandbox/src/sandbox_factory.h"
9 #include "sandbox/src/target_services.h" 9 #include "sandbox/src/target_services.h"
10 10
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 210
211 ULONG process_id; 211 ULONG process_id;
212 NTSTATUS ret = GetProcessId(process, &process_id); 212 NTSTATUS ret = GetProcessId(process, &process_id);
213 if (!NT_SUCCESS(ret)) 213 if (!NT_SUCCESS(ret))
214 return false; 214 return false;
215 215
216 return (process_id == s_process_id); 216 return (process_id == s_process_id);
217 } 217 }
218 218
219 bool IsValidImageSection(HANDLE section, PVOID *base, PLARGE_INTEGER offset, 219 bool IsValidImageSection(HANDLE section, PVOID *base, PLARGE_INTEGER offset,
220 PULONG view_size) { 220 PSIZE_T view_size) {
221 if (!section || !base || !view_size || offset) 221 if (!section || !base || !view_size || offset)
222 return false; 222 return false;
223 223
224 HANDLE query_section; 224 HANDLE query_section;
225 225
226 NTSTATUS ret = g_nt.DuplicateObject(NtCurrentProcess, section, 226 NTSTATUS ret = g_nt.DuplicateObject(NtCurrentProcess, section,
227 NtCurrentProcess, &query_section, 227 NtCurrentProcess, &query_section,
228 SECTION_QUERY, 0, 0); 228 SECTION_QUERY, 0, 0);
229 if (!NT_SUCCESS(ret)) 229 if (!NT_SUCCESS(ret))
230 return false; 230 return false;
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 if ((ix == start_pos) && sep) 359 if ((ix == start_pos) && sep)
360 return NULL; 360 return NULL;
361 361
362 // No path separator found. Use the entire name. 362 // No path separator found. Use the entire name.
363 if (!sep) { 363 if (!sep) {
364 sep = &module_path->Buffer[-1]; 364 sep = &module_path->Buffer[-1];
365 } 365 }
366 366
367 // Add one to the size so we can null terminate the string. 367 // Add one to the size so we can null terminate the string.
368 size_t size_bytes = (start_pos - ix + 1) * sizeof(wchar_t); 368 size_t size_bytes = (start_pos - ix + 1) * sizeof(wchar_t);
369
370 // Based on the code above, size_bytes should always be small enough
371 // to make the static_cast below safe.
372 DCHECK_NT(kuint16max > size_bytes);
369 char* str_buffer = new(NT_ALLOC) char[size_bytes + sizeof(UNICODE_STRING)]; 373 char* str_buffer = new(NT_ALLOC) char[size_bytes + sizeof(UNICODE_STRING)];
370 if (!str_buffer) 374 if (!str_buffer)
371 return NULL; 375 return NULL;
372 376
373 UNICODE_STRING* out_string = reinterpret_cast<UNICODE_STRING*>(str_buffer); 377 UNICODE_STRING* out_string = reinterpret_cast<UNICODE_STRING*>(str_buffer);
374 out_string->Buffer = reinterpret_cast<wchar_t*>(&out_string[1]); 378 out_string->Buffer = reinterpret_cast<wchar_t*>(&out_string[1]);
375 out_string->Length = size_bytes - sizeof(wchar_t); 379 out_string->Length = static_cast<USHORT>(size_bytes - sizeof(wchar_t));
376 out_string->MaximumLength = size_bytes; 380 out_string->MaximumLength = static_cast<USHORT>(size_bytes);
377 381
378 NTSTATUS ret = CopyData(out_string->Buffer, &sep[1], out_string->Length); 382 NTSTATUS ret = CopyData(out_string->Buffer, &sep[1], out_string->Length);
379 if (!NT_SUCCESS(ret)) { 383 if (!NT_SUCCESS(ret)) {
380 operator delete(out_string, NT_ALLOC); 384 operator delete(out_string, NT_ALLOC);
381 return NULL; 385 return NULL;
382 } 386 }
383 387
384 out_string->Buffer[out_string->Length / sizeof(wchar_t)] = L'\0'; 388 out_string->Buffer[out_string->Length / sizeof(wchar_t)] = L'\0';
385 return out_string; 389 return out_string;
386 } 390 }
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 UNREFERENCED_PARAMETER(type); 498 UNREFERENCED_PARAMETER(type);
495 return buffer; 499 return buffer;
496 } 500 }
497 501
498 void __cdecl operator delete(void* memory, void* buffer, 502 void __cdecl operator delete(void* memory, void* buffer,
499 sandbox::AllocationType type) { 503 sandbox::AllocationType type) {
500 UNREFERENCED_PARAMETER(memory); 504 UNREFERENCED_PARAMETER(memory);
501 UNREFERENCED_PARAMETER(buffer); 505 UNREFERENCED_PARAMETER(buffer);
502 UNREFERENCED_PARAMETER(type); 506 UNREFERENCED_PARAMETER(type);
503 } 507 }
OLDNEW
« no previous file with comments | « sandbox/src/sandbox_nt_util.h ('k') | sandbox/src/service_resolver.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698