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

Unified Diff: vm/dart_api_impl.cc

Issue 10782016: Enforce length/size limits for variable size heap object in order to (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 5 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
Index: vm/dart_api_impl.cc
===================================================================
--- vm/dart_api_impl.cc (revision 9641)
+++ vm/dart_api_impl.cc (working copy)
@@ -1579,6 +1579,14 @@
intptr_t length) {
Isolate* isolate = Isolate::Current();
DARTSCOPE(isolate);
+ if (codepoints == NULL) {
+ RETURN_NULL_ERROR(codepoints);
+ }
+ if (length < 0 || length > OneByteString::kMaxElements) {
+ return Api::NewError(
+ "%s expects argument 'length' to be in the range [0..%ld].",
+ CURRENT_FUNC, OneByteString::kMaxElements);
+ }
return Api::NewHandle(isolate, String::New(codepoints, length));
}
@@ -1587,6 +1595,14 @@
intptr_t length) {
Isolate* isolate = Isolate::Current();
DARTSCOPE(isolate);
+ if (codepoints == NULL) {
+ RETURN_NULL_ERROR(codepoints);
+ }
+ if (length < 0 || length > TwoByteString::kMaxElements) {
+ return Api::NewError(
+ "%s expects argument 'length' to be in the range [0..%ld].",
+ CURRENT_FUNC, TwoByteString::kMaxElements);
+ }
return Api::NewHandle(isolate, String::New(codepoints, length));
}
@@ -1595,6 +1611,14 @@
intptr_t length) {
Isolate* isolate = Isolate::Current();
DARTSCOPE(isolate);
+ if (codepoints == NULL) {
+ RETURN_NULL_ERROR(codepoints);
+ }
+ if (length < 0 || length > FourByteString::kMaxElements) {
+ return Api::NewError(
+ "%s expects argument 'length' to be in the range [0..%ld].",
+ CURRENT_FUNC, FourByteString::kMaxElements);
+ }
return Api::NewHandle(isolate, String::New(codepoints, length));
}
@@ -1652,9 +1676,10 @@
if (codepoints == NULL && length != 0) {
RETURN_NULL_ERROR(codepoints);
}
- if (length < 0) {
- return Api::NewError("%s expects argument 'length' to be greater than 0.",
- CURRENT_FUNC);
+ if (length < 0 || length > ExternalTwoByteString::kMaxElements) {
+ return Api::NewError(
+ "%s expects argument 'length' to be in the range [0..%ld].",
+ CURRENT_FUNC, ExternalTwoByteString::kMaxElements);
}
return Api::NewHandle(
isolate, String::NewExternal(codepoints, length, peer, callback));
@@ -1670,9 +1695,10 @@
if (codepoints == NULL && length != 0) {
RETURN_NULL_ERROR(codepoints);
}
- if (length < 0) {
- return Api::NewError("%s expects argument 'length' to be greater than 0.",
- CURRENT_FUNC);
+ if (length < 0 || length > ExternalFourByteString::kMaxElements) {
+ return Api::NewError(
+ "%s expects argument 'length' to be in the range [0..%ld].",
+ CURRENT_FUNC, ExternalFourByteString::kMaxElements);
}
return Api::NewHandle(
isolate, String::NewExternal(codepoints, length, peer, callback));
@@ -1823,6 +1849,11 @@
DART_EXPORT Dart_Handle Dart_NewList(intptr_t length) {
Isolate* isolate = Isolate::Current();
DARTSCOPE(isolate);
+ if (length < 0 || length > Array::kMaxElements) {
+ return Api::NewError(
+ "%s expects argument 'length' to be in the range [0..%ld].",
+ CURRENT_FUNC, Array::kMaxElements);
+ }
return Api::NewHandle(isolate, Array::New(length));
}

Powered by Google App Engine
This is Rietveld 408576698