am 9bd7afc0: Prevent integer overflow when allocating native_handle_t
* commit '9bd7afc0a1de9589c13355178b6edc709bd0bddf': Prevent integer overflow when allocating native_handle_t
This commit is contained in:
commit
e8582d65ea
1 changed files with 13 additions and 5 deletions
|
|
@ -25,14 +25,22 @@
|
||||||
#include <cutils/log.h>
|
#include <cutils/log.h>
|
||||||
#include <cutils/native_handle.h>
|
#include <cutils/native_handle.h>
|
||||||
|
|
||||||
|
static const int kMaxNativeFds = 1024;
|
||||||
|
static const int kMaxNativeInts = 1024;
|
||||||
|
|
||||||
native_handle_t* native_handle_create(int numFds, int numInts)
|
native_handle_t* native_handle_create(int numFds, int numInts)
|
||||||
{
|
{
|
||||||
native_handle_t* h = malloc(
|
if (numFds < 0 || numInts < 0 || numFds > kMaxNativeFds || numInts > kMaxNativeInts) {
|
||||||
sizeof(native_handle_t) + sizeof(int)*(numFds+numInts));
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
h->version = sizeof(native_handle_t);
|
size_t mallocSize = sizeof(native_handle_t) + (sizeof(int) * (numFds + numInts));
|
||||||
h->numFds = numFds;
|
native_handle_t* h = malloc(mallocSize);
|
||||||
h->numInts = numInts;
|
if (h) {
|
||||||
|
h->version = sizeof(native_handle_t);
|
||||||
|
h->numFds = numFds;
|
||||||
|
h->numInts = numInts;
|
||||||
|
}
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue