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

Unified Diff: src/utils.cc

Issue 14018010: Fix OOB write in --print-code. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 8 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 | « src/disassembler.cc ('k') | src/v8utils.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/utils.cc
diff --git a/src/utils.cc b/src/utils.cc
index 7e8c088dd492dc527e9803204ff6de9b2f5ab7d2..71eaea55d261989a58af4381e20b147fc1b3ddb0 100644
--- a/src/utils.cc
+++ b/src/utils.cc
@@ -46,7 +46,7 @@ void SimpleStringBuilder::AddString(const char* s) {
void SimpleStringBuilder::AddSubstring(const char* s, int n) {
- ASSERT(!is_finalized() && position_ + n < buffer_.length());
+ ASSERT(!is_finalized() && position_ + n <= buffer_.length());
ASSERT(static_cast<size_t>(n) <= strlen(s));
memcpy(&buffer_[position_], s, n * kCharSize);
position_ += n;
@@ -79,7 +79,13 @@ void SimpleStringBuilder::AddDecimalInteger(int32_t value) {
char* SimpleStringBuilder::Finalize() {
- ASSERT(!is_finalized() && position_ < buffer_.length());
+ ASSERT(!is_finalized() && position_ <= buffer_.length());
+ // If there is no space for null termination, overwrite last character.
+ if (position_ == buffer_.length()) {
+ position_--;
+ // Print ellipsis.
+ for (int i = 3; i > 0 && position_ > i; --i) buffer_[position_ - i] = '.';
+ }
buffer_[position_] = '\0';
// Make sure nobody managed to add a 0-character to the
// buffer while building the string.
« no previous file with comments | « src/disassembler.cc ('k') | src/v8utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698