libutils: fix overflow in String8::allocFromUTF8
Patch contributed in:
https://code.google.com/p/android/issues/detail?id=182908
Bug: 23290056
(cherry picked from commit 4eeacbeec0ae66e9d9395abbf83666709f2e11e3)
Change-Id: Ife1dc0791040150132bea6884f1e6c8d31972d1b
(cherry picked from commit ebabef275283f771151ec93c17469374b789b2c8)
diff --git a/libutils/String8.cpp b/libutils/String8.cpp
index e852d77..e5a48e5 100644
--- a/libutils/String8.cpp
+++ b/libutils/String8.cpp
@@ -78,6 +78,9 @@
static char* allocFromUTF8(const char* in, size_t len)
{
if (len > 0) {
+ if (len == SIZE_MAX) {
+ return NULL;
+ }
SharedBuffer* buf = SharedBuffer::alloc(len+1);
ALOG_ASSERT(buf, "Unable to allocate shared buffer");
if (buf) {