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

Unified Diff: src/messages.cc

Issue 1191263002: Protect error message formatter against invalid string length. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 6 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 | src/string-builder.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/messages.cc
diff --git a/src/messages.cc b/src/messages.cc
index ce6375594f497470f2d4b7564021b933ed91aaf3..a69df0463a892b8dbcbc93d828cc726b7ace9906 100644
--- a/src/messages.cc
+++ b/src/messages.cc
@@ -331,6 +331,7 @@ MaybeHandle<String> MessageTemplate::FormatMessage(int template_index,
Handle<String> arg0,
Handle<String> arg1,
Handle<String> arg2) {
+ static const int kMaxArgLength = 256;
Isolate* isolate = arg0->GetIsolate();
const char* template_string;
switch (template_index) {
@@ -358,7 +359,17 @@ MaybeHandle<String> MessageTemplate::FormatMessage(int template_index,
builder.AppendCharacter('%');
} else {
DCHECK(i < arraysize(args));
- builder.AppendString(args[i++]);
+ Handle<String> arg = args[i++];
+ int length = arg->length();
+ if (length > kMaxArgLength) {
+ builder.AppendString(
+ isolate->factory()->NewSubString(arg, 0, kMaxArgLength - 6));
+ builder.AppendCString("...");
+ builder.AppendString(
+ isolate->factory()->NewSubString(arg, length - 3, length));
+ } else {
+ builder.AppendString(arg);
+ }
}
} else {
builder.AppendCharacter(*c);
« no previous file with comments | « no previous file | src/string-builder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698