summaryrefslogtreecommitdiffstats
path: root/libs/ui
diff options
context:
space:
mode:
authorMichael Lentine <mlentine@google.com>2014-12-02 18:04:09 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2014-12-02 18:04:09 +0000
commitd6308379d9ddf946f5ce60fa2d0b809fa1238a63 (patch)
treeee4ab9c3cde1be9a89d306a987760ba941f6e15c /libs/ui
parent3c648e373a44237c1924fc886daf8418a6e9f4cf (diff)
parent76ebd319d96494049a2a598f4449c0ec417220f6 (diff)
downloadframeworks_native-d6308379d9ddf946f5ce60fa2d0b809fa1238a63.zip
frameworks_native-d6308379d9ddf946f5ce60fa2d0b809fa1238a63.tar.gz
frameworks_native-d6308379d9ddf946f5ce60fa2d0b809fa1238a63.tar.bz2
am 76ebd319: am 3d89edca: am e6f7a44e: Fix for corruption when numFds or numInts is too large.
* commit '76ebd319d96494049a2a598f4449c0ec417220f6': Fix for corruption when numFds or numInts is too large.
Diffstat (limited to 'libs/ui')
-rw-r--r--libs/ui/GraphicBuffer.cpp17
1 files changed, 16 insertions, 1 deletions
diff --git a/libs/ui/GraphicBuffer.cpp b/libs/ui/GraphicBuffer.cpp
index 96a7188..a93b349 100644
--- a/libs/ui/GraphicBuffer.cpp
+++ b/libs/ui/GraphicBuffer.cpp
@@ -251,10 +251,19 @@ status_t GraphicBuffer::unflatten(
const size_t numFds = buf[6];
const size_t numInts = buf[7];
+ 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 = (8 + 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) {
@@ -269,6 +278,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[8], numInts*sizeof(int));
handle = h;