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

Side by Side Diff: runtime/vm/disassembler_x64.cc

Issue 11092099: Guard against buffer overflow in the x64 disassembler. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 2 months 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 | « no previous file | 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 Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/disassembler.h" 5 #include "vm/disassembler.h"
6 6
7 #include "vm/globals.h" // Needed here to get TARGET_ARCH_IA32. 7 #include "vm/globals.h" // Needed here to get TARGET_ARCH_IA32.
8 #if defined(TARGET_ARCH_X64) 8 #if defined(TARGET_ARCH_X64)
9 #include "platform/utils.h" 9 #include "platform/utils.h"
10 #include "vm/allocation.h" 10 #include "vm/allocation.h"
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 // Byte size operand override. 420 // Byte size operand override.
421 bool byte_size_operand_; 421 bool byte_size_operand_;
422 422
423 DISALLOW_COPY_AND_ASSIGN(DisassemblerX64); 423 DISALLOW_COPY_AND_ASSIGN(DisassemblerX64);
424 }; 424 };
425 425
426 426
427 // Append the str to the output buffer. 427 // Append the str to the output buffer.
428 void DisassemblerX64::AppendToBuffer(const char* format, ...) { 428 void DisassemblerX64::AppendToBuffer(const char* format, ...) {
429 char* buf = buffer_ + buffer_pos_; 429 char* buf = buffer_ + buffer_pos_;
430 intptr_t available = buffer_size_ - buffer_pos_;
431 if (available <= 1) return; // Space for '\0' terminator.
Erik Corry 2012/10/12 08:06:27 Perhaps assert that the null char is there.
Kevin Millikin (Google) 2012/10/12 08:12:04 Done.
430 va_list args; 432 va_list args;
431 va_start(args, format); 433 va_start(args, format);
432 int retval = OS::VSNPrint(buf, buffer_size_, format, args); 434 int length = OS::VSNPrint(buf, available, format, args);
433 va_end(args); 435 va_end(args);
434 buffer_pos_ += retval; 436 buffer_pos_ =
437 (length >= available) ? (buffer_size_ - 1) : (buffer_pos_ + length);
438 ASSERT(buffer_pos_ < buffer_size_);
435 } 439 }
436 440
437 441
438 int DisassemblerX64::PrintRightOperandHelper( 442 int DisassemblerX64::PrintRightOperandHelper(
439 uint8_t* modrmp, 443 uint8_t* modrmp,
440 RegisterNameMapping direct_register_name) { 444 RegisterNameMapping direct_register_name) {
441 int mod, regop, rm; 445 int mod, regop, rm;
442 get_modrm(*modrmp, &mod, &regop, &rm); 446 get_modrm(*modrmp, &mod, &regop, &rm);
443 RegisterNameMapping register_name = (mod == 3) ? direct_register_name : 447 RegisterNameMapping register_name = (mod == 3) ? direct_register_name :
444 &DisassemblerX64::NameOfCPURegister; 448 &DisassemblerX64::NameOfCPURegister;
(...skipping 1349 matching lines...) Expand 10 before | Expand all | Expand 10 after
1794 case 0xF7: 1798 case 0xF7:
1795 data += F6F7Instruction(data); 1799 data += F6F7Instruction(data);
1796 break; 1800 break;
1797 1801
1798 default: 1802 default:
1799 UnimplementedInstruction(); 1803 UnimplementedInstruction();
1800 data += 1; 1804 data += 1;
1801 } 1805 }
1802 } // !processed 1806 } // !processed
1803 1807
1804 if (buffer_pos_ < buffer_size_) { 1808 ASSERT(buffer_[buffer_pos_] == '\0');
1805 buffer_[buffer_pos_] = '\0';
1806 }
1807 1809
1808 int instr_len = data - reinterpret_cast<uint8_t*>(pc); 1810 int instr_len = data - reinterpret_cast<uint8_t*>(pc);
1809 ASSERT(instr_len > 0); // Ensure progress. 1811 ASSERT(instr_len > 0); // Ensure progress.
1810 1812
1811 return instr_len; 1813 return instr_len;
1812 } 1814 }
1813 1815
1814 1816
1815 int Disassembler::DecodeInstruction(char* hex_buffer, intptr_t hex_size, 1817 int Disassembler::DecodeInstruction(char* hex_buffer, intptr_t hex_size,
1816 char* human_buffer, intptr_t human_size, 1818 char* human_buffer, intptr_t human_size,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1859 human_buffer, 1861 human_buffer,
1860 sizeof(human_buffer), 1862 sizeof(human_buffer),
1861 pc); 1863 pc);
1862 pc += instruction_length; 1864 pc += instruction_length;
1863 } 1865 }
1864 } 1866 }
1865 1867
1866 } // namespace dart 1868 } // namespace dart
1867 1869
1868 #endif // defined TARGET_ARCH_X64 1870 #endif // defined TARGET_ARCH_X64
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698