system/core
Revision | 4105d377f4552a702de48051208926b08e574d17 (tree) |
---|---|
Time | 2018-05-25 19:29:03 |
Author | Chih-Wei Huang <cwhuang@linu...> |
Commiter | Chih-Wei Huang |
Merge tag 'android-8.1.0_r29' into oreo-x86
Android 8.1.0 Release 29 (OPM4.171019.016.C1)
@@ -79,6 +79,23 @@ static char16_t* allocFromUTF8(const char* u8str, size_t u8len) | ||
79 | 79 | return getEmptyString(); |
80 | 80 | } |
81 | 81 | |
82 | +static char16_t* allocFromUTF16(const char16_t* u16str, size_t u16len) { | |
83 | + if (u16len >= SIZE_MAX / sizeof(char16_t)) { | |
84 | + android_errorWriteLog(0x534e4554, "73826242"); | |
85 | + abort(); | |
86 | + } | |
87 | + | |
88 | + SharedBuffer* buf = SharedBuffer::alloc((u16len + 1) * sizeof(char16_t)); | |
89 | + ALOG_ASSERT(buf, "Unable to allocate shared buffer"); | |
90 | + if (buf) { | |
91 | + char16_t* str = (char16_t*)buf->data(); | |
92 | + memcpy(str, u16str, u16len * sizeof(char16_t)); | |
93 | + str[u16len] = 0; | |
94 | + return str; | |
95 | + } | |
96 | + return getEmptyString(); | |
97 | +} | |
98 | + | |
82 | 99 | // --------------------------------------------------------------------------- |
83 | 100 | |
84 | 101 | String16::String16() |
@@ -111,35 +128,9 @@ String16::String16(const String16& o, size_t len, size_t begin) | ||
111 | 128 | setTo(o, len, begin); |
112 | 129 | } |
113 | 130 | |
114 | -String16::String16(const char16_t* o) | |
115 | -{ | |
116 | - size_t len = strlen16(o); | |
117 | - SharedBuffer* buf = SharedBuffer::alloc((len+1)*sizeof(char16_t)); | |
118 | - ALOG_ASSERT(buf, "Unable to allocate shared buffer"); | |
119 | - if (buf) { | |
120 | - char16_t* str = (char16_t*)buf->data(); | |
121 | - strcpy16(str, o); | |
122 | - mString = str; | |
123 | - return; | |
124 | - } | |
125 | - | |
126 | - mString = getEmptyString(); | |
127 | -} | |
128 | - | |
129 | -String16::String16(const char16_t* o, size_t len) | |
130 | -{ | |
131 | - SharedBuffer* buf = SharedBuffer::alloc((len+1)*sizeof(char16_t)); | |
132 | - ALOG_ASSERT(buf, "Unable to allocate shared buffer"); | |
133 | - if (buf) { | |
134 | - char16_t* str = (char16_t*)buf->data(); | |
135 | - memcpy(str, o, len*sizeof(char16_t)); | |
136 | - str[len] = 0; | |
137 | - mString = str; | |
138 | - return; | |
139 | - } | |
131 | +String16::String16(const char16_t* o) : mString(allocFromUTF16(o, strlen16(o))) {} | |
140 | 132 | |
141 | - mString = getEmptyString(); | |
142 | -} | |
133 | +String16::String16(const char16_t* o, size_t len) : mString(allocFromUTF16(o, len)) {} | |
143 | 134 | |
144 | 135 | String16::String16(const String8& o) |
145 | 136 | : mString(allocFromUTF8(o.string(), o.size())) |
@@ -201,6 +192,11 @@ status_t String16::setTo(const char16_t* other) | ||
201 | 192 | |
202 | 193 | status_t String16::setTo(const char16_t* other, size_t len) |
203 | 194 | { |
195 | + if (len >= SIZE_MAX / sizeof(char16_t)) { | |
196 | + android_errorWriteLog(0x534e4554, "73826242"); | |
197 | + abort(); | |
198 | + } | |
199 | + | |
204 | 200 | SharedBuffer* buf = SharedBuffer::bufferFromData(mString) |
205 | 201 | ->editResize((len+1)*sizeof(char16_t)); |
206 | 202 | if (buf) { |
@@ -224,6 +220,11 @@ status_t String16::append(const String16& other) | ||
224 | 220 | return NO_ERROR; |
225 | 221 | } |
226 | 222 | |
223 | + if (myLen >= SIZE_MAX / sizeof(char16_t) - otherLen) { | |
224 | + android_errorWriteLog(0x534e4554, "73826242"); | |
225 | + abort(); | |
226 | + } | |
227 | + | |
227 | 228 | SharedBuffer* buf = SharedBuffer::bufferFromData(mString) |
228 | 229 | ->editResize((myLen+otherLen+1)*sizeof(char16_t)); |
229 | 230 | if (buf) { |
@@ -245,6 +246,11 @@ status_t String16::append(const char16_t* chrs, size_t otherLen) | ||
245 | 246 | return NO_ERROR; |
246 | 247 | } |
247 | 248 | |
249 | + if (myLen >= SIZE_MAX / sizeof(char16_t) - otherLen) { | |
250 | + android_errorWriteLog(0x534e4554, "73826242"); | |
251 | + abort(); | |
252 | + } | |
253 | + | |
248 | 254 | SharedBuffer* buf = SharedBuffer::bufferFromData(mString) |
249 | 255 | ->editResize((myLen+otherLen+1)*sizeof(char16_t)); |
250 | 256 | if (buf) { |