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

Side by Side Diff: courgette/disassembler_win32_x86.cc

Issue 8501023: Fix two pointer arithmetic errors. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Fix another < versus <= Created 9 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 | « courgette/disassembler_elf_32_x86_unittest.cc ('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) 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 "courgette/disassembler_win32_x86.h" 5 #include "courgette/disassembler_win32_x86.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 } 459 }
460 460
461 //while (abs32_pos != abs32_locations_.end() && *abs32_pos < current_rva) 461 //while (abs32_pos != abs32_locations_.end() && *abs32_pos < current_rva)
462 // ++abs32_pos; 462 // ++abs32_pos;
463 463
464 // Heuristic discovery of rel32 locations in instruction stream: are the 464 // Heuristic discovery of rel32 locations in instruction stream: are the
465 // next few bytes the start of an instruction containing a rel32 465 // next few bytes the start of an instruction containing a rel32
466 // addressing mode? 466 // addressing mode?
467 const uint8* rel32 = NULL; 467 const uint8* rel32 = NULL;
468 468
469 if (p + 5 < end_pointer) { 469 if (p + 5 <= end_pointer) {
470 if (*p == 0xE8 || *p == 0xE9) { // jmp rel32 and call rel32 470 if (*p == 0xE8 || *p == 0xE9) { // jmp rel32 and call rel32
471 rel32 = p + 1; 471 rel32 = p + 1;
472 } 472 }
473 } 473 }
474 if (p + 6 < end_pointer) { 474 if (p + 6 <= end_pointer) {
475 if (*p == 0x0F && (*(p+1) & 0xF0) == 0x80) { // Jcc long form 475 if (*p == 0x0F && (*(p+1) & 0xF0) == 0x80) { // Jcc long form
476 if (p[1] != 0x8A && p[1] != 0x8B) // JPE/JPO unlikely 476 if (p[1] != 0x8A && p[1] != 0x8B) // JPE/JPO unlikely
477 rel32 = p + 2; 477 rel32 = p + 2;
478 } 478 }
479 } 479 }
480 if (rel32) { 480 if (rel32) {
481 RVA rel32_rva = static_cast<RVA>(rel32 - adjust_pointer_to_rva); 481 RVA rel32_rva = static_cast<RVA>(rel32 - adjust_pointer_to_rva);
482 482
483 // Is there an abs32 reloc overlapping the candidate? 483 // Is there an abs32 reloc overlapping the candidate?
484 while (abs32_pos != abs32_locations_.end() && *abs32_pos < rel32_rva - 3) 484 while (abs32_pos != abs32_locations_.end() && *abs32_pos < rel32_rva - 3)
(...skipping 11 matching lines...) Expand all
496 496
497 RVA target_rva = rel32_rva + 4 + Read32LittleEndian(rel32); 497 RVA target_rva = rel32_rva + 4 + Read32LittleEndian(rel32);
498 // To be valid, rel32 target must be within image, and within this 498 // To be valid, rel32 target must be within image, and within this
499 // section. 499 // section.
500 if (IsValidRVA(target_rva) && 500 if (IsValidRVA(target_rva) &&
501 start_rva <= target_rva && target_rva < end_rva) { 501 start_rva <= target_rva && target_rva < end_rva) {
502 rel32_locations_.push_back(rel32_rva); 502 rel32_locations_.push_back(rel32_rva);
503 #if COURGETTE_HISTOGRAM_TARGETS 503 #if COURGETTE_HISTOGRAM_TARGETS
504 ++rel32_target_rvas_[target_rva]; 504 ++rel32_target_rvas_[target_rva];
505 #endif 505 #endif
506 p += 4; 506 p = rel32 + 4;
507 continue; 507 continue;
508 } 508 }
509 } 509 }
510 p += 1; 510 p += 1;
511 } 511 }
512 } 512 }
513 513
514 CheckBool DisassemblerWin32X86::ParseNonSectionFileRegion( 514 CheckBool DisassemblerWin32X86::ParseNonSectionFileRegion(
515 uint32 start_file_offset, 515 uint32 start_file_offset,
516 uint32 end_file_offset, 516 uint32 end_file_offset,
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 directory->size_ = static_cast<uint32>(size); 726 directory->size_ = static_cast<uint32>(size);
727 return true; 727 return true;
728 } else { 728 } else {
729 directory->address_ = 0; 729 directory->address_ = 0;
730 directory->size_ = 0; 730 directory->size_ = 0;
731 return true; 731 return true;
732 } 732 }
733 } 733 }
734 734
735 } // namespace courgette 735 } // namespace courgette
OLDNEW
« no previous file with comments | « courgette/disassembler_elf_32_x86_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698