OSDN Git Service

Verify that the native handle was created
authorAdam Lesinski <adamlesinski@google.com>
Wed, 13 May 2015 00:35:48 +0000 (17:35 -0700)
committerZach Riggle <riggle@google.com>
Wed, 13 May 2015 17:16:00 +0000 (17:16 +0000)
The inputs to native_handle_create can cause an overflowed allocation,
so check the return value of native_handle_create before accessing
the memory it returns.

Bug:19334482
Change-Id: I1f489382776c2a1390793a79dc27ea17baa9b2a2
(cherry picked from commit eaac99a7172da52a76ba48c26413778a74951b1a)

libs/binder/Parcel.cpp

index db9e0a1..e5a2871 100644 (file)
@@ -1144,6 +1144,10 @@ native_handle* Parcel::readNativeHandle() const
     if (err != NO_ERROR) return 0;
 
     native_handle* h = native_handle_create(numFds, numInts);
+    if (!h) {
+        return 0;
+    }
+
     for (int i=0 ; err==NO_ERROR && i<numFds ; i++) {
         h->data[i] = dup(readFileDescriptor());
         if (h->data[i] < 0) err = BAD_VALUE;