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