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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/disassembler_x64.cc
diff --git a/runtime/vm/disassembler_x64.cc b/runtime/vm/disassembler_x64.cc
index 5cac646df8862e751b42d07970abcf10ae6f6a16..67bb5edfc95ef9528092d36634b7609cfdfa2bbc 100644
--- a/runtime/vm/disassembler_x64.cc
+++ b/runtime/vm/disassembler_x64.cc
@@ -427,11 +427,15 @@ class DisassemblerX64 : public ValueObject {
// Append the str to the output buffer.
void DisassemblerX64::AppendToBuffer(const char* format, ...) {
char* buf = buffer_ + buffer_pos_;
+ intptr_t available = buffer_size_ - buffer_pos_;
+ 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.
va_list args;
va_start(args, format);
- int retval = OS::VSNPrint(buf, buffer_size_, format, args);
+ int length = OS::VSNPrint(buf, available, format, args);
va_end(args);
- buffer_pos_ += retval;
+ buffer_pos_ =
+ (length >= available) ? (buffer_size_ - 1) : (buffer_pos_ + length);
+ ASSERT(buffer_pos_ < buffer_size_);
}
@@ -1801,9 +1805,7 @@ int DisassemblerX64::InstructionDecode(uword pc) {
}
} // !processed
- if (buffer_pos_ < buffer_size_) {
- buffer_[buffer_pos_] = '\0';
- }
+ ASSERT(buffer_[buffer_pos_] == '\0');
int instr_len = data - reinterpret_cast<uint8_t*>(pc);
ASSERT(instr_len > 0); // Ensure progress.
« 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