OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/win/src/sandbox_nt_util.h" | 5 #include "sandbox/win/src/sandbox_nt_util.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/win/pe_image.h" | 9 #include "base/win/pe_image.h" |
10 #include "sandbox/win/src/sandbox_factory.h" | 10 #include "sandbox/win/src/sandbox_factory.h" |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 operator delete(handle_name, NT_ALLOC); | 283 operator delete(handle_name, NT_ALLOC); |
284 handle_name = NULL; | 284 handle_name = NULL; |
285 } | 285 } |
286 } | 286 } |
287 | 287 |
288 return ret; | 288 return ret; |
289 } | 289 } |
290 | 290 |
291 // Hacky code... replace with AllocAndCopyObjectAttributes. | 291 // Hacky code... replace with AllocAndCopyObjectAttributes. |
292 NTSTATUS AllocAndCopyName(const OBJECT_ATTRIBUTES* in_object, | 292 NTSTATUS AllocAndCopyName(const OBJECT_ATTRIBUTES* in_object, |
293 wchar_t** out_name, | 293 wchar_t** out_name, uint32* attributes, |
294 uint32_t* attributes, | |
295 HANDLE* root) { | 294 HANDLE* root) { |
296 if (!InitHeap()) | 295 if (!InitHeap()) |
297 return STATUS_NO_MEMORY; | 296 return STATUS_NO_MEMORY; |
298 | 297 |
299 DCHECK_NT(out_name); | 298 DCHECK_NT(out_name); |
300 *out_name = NULL; | 299 *out_name = NULL; |
301 NTSTATUS ret = STATUS_UNSUCCESSFUL; | 300 NTSTATUS ret = STATUS_UNSUCCESSFUL; |
302 __try { | 301 __try { |
303 do { | 302 do { |
304 if (in_object->RootDirectory != static_cast<HANDLE>(0) && !root) | 303 if (in_object->RootDirectory != static_cast<HANDLE>(0) && !root) |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 alloc_destination); | 426 alloc_destination); |
428 DCHECK_NT(STATUS_BUFFER_OVERFLOW != ret); | 427 DCHECK_NT(STATUS_BUFFER_OVERFLOW != ret); |
429 if (!NT_SUCCESS(ret)) { | 428 if (!NT_SUCCESS(ret)) { |
430 operator delete(out_string, NT_ALLOC); | 429 operator delete(out_string, NT_ALLOC); |
431 return NULL; | 430 return NULL; |
432 } | 431 } |
433 | 432 |
434 return out_string; | 433 return out_string; |
435 } | 434 } |
436 | 435 |
437 UNICODE_STRING* GetImageInfoFromModule(HMODULE module, uint32_t* flags) { | 436 UNICODE_STRING* GetImageInfoFromModule(HMODULE module, uint32* flags) { |
438 // PEImage's dtor won't be run during SEH unwinding, but that's OK. | 437 // PEImage's dtor won't be run during SEH unwinding, but that's OK. |
439 #pragma warning(push) | 438 #pragma warning(push) |
440 #pragma warning(disable: 4509) | 439 #pragma warning(disable: 4509) |
441 UNICODE_STRING* out_name = NULL; | 440 UNICODE_STRING* out_name = NULL; |
442 __try { | 441 __try { |
443 do { | 442 do { |
444 *flags = 0; | 443 *flags = 0; |
445 base::win::PEImage pe(module); | 444 base::win::PEImage pe(module); |
446 | 445 |
447 if (!pe.VerifyMagic()) | 446 if (!pe.VerifyMagic()) |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 // No path separator found. Use the entire name. | 522 // No path separator found. Use the entire name. |
524 if (!sep) { | 523 if (!sep) { |
525 sep = &module_path->Buffer[-1]; | 524 sep = &module_path->Buffer[-1]; |
526 } | 525 } |
527 | 526 |
528 // Add one to the size so we can null terminate the string. | 527 // Add one to the size so we can null terminate the string. |
529 size_t size_bytes = (start_pos - ix + 1) * sizeof(wchar_t); | 528 size_t size_bytes = (start_pos - ix + 1) * sizeof(wchar_t); |
530 | 529 |
531 // Based on the code above, size_bytes should always be small enough | 530 // Based on the code above, size_bytes should always be small enough |
532 // to make the static_cast below safe. | 531 // to make the static_cast below safe. |
533 DCHECK_NT(UINT16_MAX > size_bytes); | 532 DCHECK_NT(kuint16max > size_bytes); |
534 char* str_buffer = new(NT_ALLOC) char[size_bytes + sizeof(UNICODE_STRING)]; | 533 char* str_buffer = new(NT_ALLOC) char[size_bytes + sizeof(UNICODE_STRING)]; |
535 if (!str_buffer) | 534 if (!str_buffer) |
536 return NULL; | 535 return NULL; |
537 | 536 |
538 UNICODE_STRING* out_string = reinterpret_cast<UNICODE_STRING*>(str_buffer); | 537 UNICODE_STRING* out_string = reinterpret_cast<UNICODE_STRING*>(str_buffer); |
539 out_string->Buffer = reinterpret_cast<wchar_t*>(&out_string[1]); | 538 out_string->Buffer = reinterpret_cast<wchar_t*>(&out_string[1]); |
540 out_string->Length = static_cast<USHORT>(size_bytes - sizeof(wchar_t)); | 539 out_string->Length = static_cast<USHORT>(size_bytes - sizeof(wchar_t)); |
541 out_string->MaximumLength = static_cast<USHORT>(size_bytes); | 540 out_string->MaximumLength = static_cast<USHORT>(size_bytes); |
542 | 541 |
543 NTSTATUS ret = CopyData(out_string->Buffer, &sep[1], out_string->Length); | 542 NTSTATUS ret = CopyData(out_string->Buffer, &sep[1], out_string->Length); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 DCHECK_NT(NT_SUCCESS(ret)); | 578 DCHECK_NT(NT_SUCCESS(ret)); |
580 | 579 |
581 changed_ = false; | 580 changed_ = false; |
582 address_ = NULL; | 581 address_ = NULL; |
583 bytes_ = 0; | 582 bytes_ = 0; |
584 old_protect_ = 0; | 583 old_protect_ = 0; |
585 | 584 |
586 return ret; | 585 return ret; |
587 } | 586 } |
588 | 587 |
589 bool IsSupportedRenameCall(FILE_RENAME_INFORMATION* file_info, | 588 bool IsSupportedRenameCall(FILE_RENAME_INFORMATION* file_info, DWORD length, |
590 DWORD length, | 589 uint32 file_info_class) { |
591 uint32_t file_info_class) { | |
592 if (FileRenameInformation != file_info_class) | 590 if (FileRenameInformation != file_info_class) |
593 return false; | 591 return false; |
594 | 592 |
595 if (length < sizeof(FILE_RENAME_INFORMATION)) | 593 if (length < sizeof(FILE_RENAME_INFORMATION)) |
596 return false; | 594 return false; |
597 | 595 |
598 // Make sure file name length doesn't exceed the message length | 596 // Make sure file name length doesn't exceed the message length |
599 if (length - offsetof(FILE_RENAME_INFORMATION, FileName) < | 597 if (length - offsetof(FILE_RENAME_INFORMATION, FileName) < |
600 file_info->FileNameLength) | 598 file_info->FileNameLength) |
601 return false; | 599 return false; |
602 | 600 |
603 // We don't support a root directory. | 601 // We don't support a root directory. |
604 if (file_info->RootDirectory) | 602 if (file_info->RootDirectory) |
605 return false; | 603 return false; |
606 | 604 |
607 static const wchar_t kPathPrefix[] = { L'\\', L'?', L'?', L'\\'}; | 605 static const wchar_t kPathPrefix[] = { L'\\', L'?', L'?', L'\\'}; |
608 | 606 |
609 // Check if it starts with \\??\\. We don't support relative paths. | 607 // Check if it starts with \\??\\. We don't support relative paths. |
610 if (file_info->FileNameLength < sizeof(kPathPrefix) || | 608 if (file_info->FileNameLength < sizeof(kPathPrefix) || |
611 file_info->FileNameLength > UINT16_MAX) | 609 file_info->FileNameLength > kuint16max) |
612 return false; | 610 return false; |
613 | 611 |
614 if (file_info->FileName[0] != kPathPrefix[0] || | 612 if (file_info->FileName[0] != kPathPrefix[0] || |
615 file_info->FileName[1] != kPathPrefix[1] || | 613 file_info->FileName[1] != kPathPrefix[1] || |
616 file_info->FileName[2] != kPathPrefix[2] || | 614 file_info->FileName[2] != kPathPrefix[2] || |
617 file_info->FileName[3] != kPathPrefix[3]) | 615 file_info->FileName[3] != kPathPrefix[3]) |
618 return false; | 616 return false; |
619 | 617 |
620 return true; | 618 return true; |
621 } | 619 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
665 | 663 |
666 void* __cdecl operator new(size_t size, | 664 void* __cdecl operator new(size_t size, |
667 void* buffer, | 665 void* buffer, |
668 sandbox::AllocationType type) { | 666 sandbox::AllocationType type) { |
669 return buffer; | 667 return buffer; |
670 } | 668 } |
671 | 669 |
672 void __cdecl operator delete(void* memory, | 670 void __cdecl operator delete(void* memory, |
673 void* buffer, | 671 void* buffer, |
674 sandbox::AllocationType type) {} | 672 sandbox::AllocationType type) {} |
OLD | NEW |