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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
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 "include/dart_api.h" 5 #include "include/dart_api.h"
6 6
7 #include "vm/bigint_operations.h" 7 #include "vm/bigint_operations.h"
8 #include "vm/class_finalizer.h" 8 #include "vm/class_finalizer.h"
9 #include "vm/compiler.h" 9 #include "vm/compiler.h"
10 #include "vm/dart.h" 10 #include "vm/dart.h"
(...skipping 1561 matching lines...) Expand 10 before | Expand all | Expand 10 after
1572 CURRENT_FUNC); 1572 CURRENT_FUNC);
1573 } 1573 }
1574 return Api::NewHandle(isolate, String::New(str)); 1574 return Api::NewHandle(isolate, String::New(str));
1575 } 1575 }
1576 1576
1577 1577
1578 DART_EXPORT Dart_Handle Dart_NewString8(const uint8_t* codepoints, 1578 DART_EXPORT Dart_Handle Dart_NewString8(const uint8_t* codepoints,
1579 intptr_t length) { 1579 intptr_t length) {
1580 Isolate* isolate = Isolate::Current(); 1580 Isolate* isolate = Isolate::Current();
1581 DARTSCOPE(isolate); 1581 DARTSCOPE(isolate);
1582 if (codepoints == NULL) {
1583 RETURN_NULL_ERROR(codepoints);
1584 }
1585 if (length < 0 || length > OneByteString::kMaxElements) {
1586 return Api::NewError(
1587 "%s expects argument 'length' to be in the range [0..%ld].",
1588 CURRENT_FUNC, OneByteString::kMaxElements);
1589 }
1582 return Api::NewHandle(isolate, String::New(codepoints, length)); 1590 return Api::NewHandle(isolate, String::New(codepoints, length));
1583 } 1591 }
1584 1592
1585 1593
1586 DART_EXPORT Dart_Handle Dart_NewString16(const uint16_t* codepoints, 1594 DART_EXPORT Dart_Handle Dart_NewString16(const uint16_t* codepoints,
1587 intptr_t length) { 1595 intptr_t length) {
1588 Isolate* isolate = Isolate::Current(); 1596 Isolate* isolate = Isolate::Current();
1589 DARTSCOPE(isolate); 1597 DARTSCOPE(isolate);
1598 if (codepoints == NULL) {
1599 RETURN_NULL_ERROR(codepoints);
1600 }
1601 if (length < 0 || length > TwoByteString::kMaxElements) {
1602 return Api::NewError(
1603 "%s expects argument 'length' to be in the range [0..%ld].",
1604 CURRENT_FUNC, TwoByteString::kMaxElements);
1605 }
1590 return Api::NewHandle(isolate, String::New(codepoints, length)); 1606 return Api::NewHandle(isolate, String::New(codepoints, length));
1591 } 1607 }
1592 1608
1593 1609
1594 DART_EXPORT Dart_Handle Dart_NewString32(const uint32_t* codepoints, 1610 DART_EXPORT Dart_Handle Dart_NewString32(const uint32_t* codepoints,
1595 intptr_t length) { 1611 intptr_t length) {
1596 Isolate* isolate = Isolate::Current(); 1612 Isolate* isolate = Isolate::Current();
1597 DARTSCOPE(isolate); 1613 DARTSCOPE(isolate);
1614 if (codepoints == NULL) {
1615 RETURN_NULL_ERROR(codepoints);
1616 }
1617 if (length < 0 || length > FourByteString::kMaxElements) {
1618 return Api::NewError(
1619 "%s expects argument 'length' to be in the range [0..%ld].",
1620 CURRENT_FUNC, FourByteString::kMaxElements);
1621 }
1598 return Api::NewHandle(isolate, String::New(codepoints, length)); 1622 return Api::NewHandle(isolate, String::New(codepoints, length));
1599 } 1623 }
1600 1624
1601 1625
1602 DART_EXPORT bool Dart_IsExternalString(Dart_Handle object) { 1626 DART_EXPORT bool Dart_IsExternalString(Dart_Handle object) {
1603 return RawObject::IsExternalStringClassId(Api::ClassId(object)); 1627 return RawObject::IsExternalStringClassId(Api::ClassId(object));
1604 } 1628 }
1605 1629
1606 1630
1607 DART_EXPORT Dart_Handle Dart_ExternalStringGetPeer(Dart_Handle object, 1631 DART_EXPORT Dart_Handle Dart_ExternalStringGetPeer(Dart_Handle object,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1645 1669
1646 DART_EXPORT Dart_Handle Dart_NewExternalString16(const uint16_t* codepoints, 1670 DART_EXPORT Dart_Handle Dart_NewExternalString16(const uint16_t* codepoints,
1647 intptr_t length, 1671 intptr_t length,
1648 void* peer, 1672 void* peer,
1649 Dart_PeerFinalizer callback) { 1673 Dart_PeerFinalizer callback) {
1650 Isolate* isolate = Isolate::Current(); 1674 Isolate* isolate = Isolate::Current();
1651 DARTSCOPE(isolate); 1675 DARTSCOPE(isolate);
1652 if (codepoints == NULL && length != 0) { 1676 if (codepoints == NULL && length != 0) {
1653 RETURN_NULL_ERROR(codepoints); 1677 RETURN_NULL_ERROR(codepoints);
1654 } 1678 }
1655 if (length < 0) { 1679 if (length < 0 || length > ExternalTwoByteString::kMaxElements) {
1656 return Api::NewError("%s expects argument 'length' to be greater than 0.", 1680 return Api::NewError(
1657 CURRENT_FUNC); 1681 "%s expects argument 'length' to be in the range [0..%ld].",
1682 CURRENT_FUNC, ExternalTwoByteString::kMaxElements);
1658 } 1683 }
1659 return Api::NewHandle( 1684 return Api::NewHandle(
1660 isolate, String::NewExternal(codepoints, length, peer, callback)); 1685 isolate, String::NewExternal(codepoints, length, peer, callback));
1661 } 1686 }
1662 1687
1663 1688
1664 DART_EXPORT Dart_Handle Dart_NewExternalString32(const uint32_t* codepoints, 1689 DART_EXPORT Dart_Handle Dart_NewExternalString32(const uint32_t* codepoints,
1665 intptr_t length, 1690 intptr_t length,
1666 void* peer, 1691 void* peer,
1667 Dart_PeerFinalizer callback) { 1692 Dart_PeerFinalizer callback) {
1668 Isolate* isolate = Isolate::Current(); 1693 Isolate* isolate = Isolate::Current();
1669 DARTSCOPE(isolate); 1694 DARTSCOPE(isolate);
1670 if (codepoints == NULL && length != 0) { 1695 if (codepoints == NULL && length != 0) {
1671 RETURN_NULL_ERROR(codepoints); 1696 RETURN_NULL_ERROR(codepoints);
1672 } 1697 }
1673 if (length < 0) { 1698 if (length < 0 || length > ExternalFourByteString::kMaxElements) {
1674 return Api::NewError("%s expects argument 'length' to be greater than 0.", 1699 return Api::NewError(
1675 CURRENT_FUNC); 1700 "%s expects argument 'length' to be in the range [0..%ld].",
1701 CURRENT_FUNC, ExternalFourByteString::kMaxElements);
1676 } 1702 }
1677 return Api::NewHandle( 1703 return Api::NewHandle(
1678 isolate, String::NewExternal(codepoints, length, peer, callback)); 1704 isolate, String::NewExternal(codepoints, length, peer, callback));
1679 } 1705 }
1680 1706
1681 1707
1682 DART_EXPORT Dart_Handle Dart_StringGet8(Dart_Handle str, 1708 DART_EXPORT Dart_Handle Dart_StringGet8(Dart_Handle str,
1683 uint8_t* codepoints, 1709 uint8_t* codepoints,
1684 intptr_t* length) { 1710 intptr_t* length) {
1685 Isolate* isolate = Isolate::Current(); 1711 Isolate* isolate = Isolate::Current();
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
1816 Isolate* isolate = Isolate::Current(); 1842 Isolate* isolate = Isolate::Current();
1817 DARTSCOPE(isolate); 1843 DARTSCOPE(isolate);
1818 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); 1844 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object));
1819 return GetListInstance(isolate, obj) != Instance::null(); 1845 return GetListInstance(isolate, obj) != Instance::null();
1820 } 1846 }
1821 1847
1822 1848
1823 DART_EXPORT Dart_Handle Dart_NewList(intptr_t length) { 1849 DART_EXPORT Dart_Handle Dart_NewList(intptr_t length) {
1824 Isolate* isolate = Isolate::Current(); 1850 Isolate* isolate = Isolate::Current();
1825 DARTSCOPE(isolate); 1851 DARTSCOPE(isolate);
1852 if (length < 0 || length > Array::kMaxElements) {
1853 return Api::NewError(
1854 "%s expects argument 'length' to be in the range [0..%ld].",
1855 CURRENT_FUNC, Array::kMaxElements);
1856 }
1826 return Api::NewHandle(isolate, Array::New(length)); 1857 return Api::NewHandle(isolate, Array::New(length));
1827 } 1858 }
1828 1859
1829 1860
1830 #define GET_LIST_LENGTH(isolate, type, obj, len) \ 1861 #define GET_LIST_LENGTH(isolate, type, obj, len) \
1831 type& array = type::Handle(isolate); \ 1862 type& array = type::Handle(isolate); \
1832 array ^= obj.raw(); \ 1863 array ^= obj.raw(); \
1833 *len = array.Length(); \ 1864 *len = array.Length(); \
1834 return Api::Success(isolate); \ 1865 return Api::Success(isolate); \
1835 1866
(...skipping 2284 matching lines...) Expand 10 before | Expand all | Expand 10 after
4120 *buffer_size = 0; 4151 *buffer_size = 0;
4121 } 4152 }
4122 } 4153 }
4123 4154
4124 4155
4125 DART_EXPORT void Dart_InitFlowGraphPrinting(FileWriterFunction function) { 4156 DART_EXPORT void Dart_InitFlowGraphPrinting(FileWriterFunction function) {
4126 Dart::set_flow_graph_writer(function); 4157 Dart::set_flow_graph_writer(function);
4127 } 4158 }
4128 4159
4129 } // namespace dart 4160 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698