diff options
author | Michael Lentine <mlentine@google.com> | 2014-11-05 19:06:19 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2014-11-05 19:06:19 +0000 |
commit | a2f27a0d63da87b23bf214355882bbcea6a163ea (patch) | |
tree | 206ca1c9f216364aadcfbb11ccc58280d16863af /libs | |
parent | 090dbeb7f174e5c1c605d8d91ef0faa2c46e9ee3 (diff) | |
parent | 26645298400c0ae3a95731388364263d6a914ee4 (diff) | |
download | frameworks_native-a2f27a0d63da87b23bf214355882bbcea6a163ea.zip frameworks_native-a2f27a0d63da87b23bf214355882bbcea6a163ea.tar.gz frameworks_native-a2f27a0d63da87b23bf214355882bbcea6a163ea.tar.bz2 |
am 26645298: Merge "Fix for corruption when numFds or numInts is too large." into lmp-mr1-dev
* commit '26645298400c0ae3a95731388364263d6a914ee4':
Fix for corruption when numFds or numInts is too large.
Diffstat (limited to 'libs')
-rw-r--r-- | libs/ui/GraphicBuffer.cpp | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/libs/ui/GraphicBuffer.cpp b/libs/ui/GraphicBuffer.cpp index 9b0bd60..e768f13 100644 --- a/libs/ui/GraphicBuffer.cpp +++ b/libs/ui/GraphicBuffer.cpp @@ -310,10 +310,19 @@ status_t GraphicBuffer::unflatten( const size_t numFds = buf[8]; const size_t numInts = buf[9]; + const size_t maxNumber = UINT_MAX / sizeof(int); + if (numFds >= maxNumber || numInts >= (maxNumber - 10)) { + width = height = stride = format = usage = 0; + handle = NULL; + ALOGE("unflatten: numFds or numInts is too large: %d, %d", + numFds, numInts); + return BAD_VALUE; + } + const size_t sizeNeeded = (10 + numInts) * sizeof(int); if (size < sizeNeeded) return NO_MEMORY; - size_t fdCountNeeded = 0; + size_t fdCountNeeded = numFds; if (count < fdCountNeeded) return NO_MEMORY; if (handle) { @@ -328,6 +337,12 @@ status_t GraphicBuffer::unflatten( format = buf[4]; usage = buf[5]; native_handle* h = native_handle_create(numFds, numInts); + if (!h) { + width = height = stride = format = usage = 0; + handle = NULL; + ALOGE("unflatten: native_handle_create failed"); + return NO_MEMORY; + } memcpy(h->data, fds, numFds*sizeof(int)); memcpy(h->data + numFds, &buf[10], numInts*sizeof(int)); handle = h; |