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

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

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

Powered by Google App Engine
This is Rietveld 408576698