summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
author Christopher Tate <ctate@google.com> 2016-02-17 18:37:52 +0000
committer android-build-merger <android-build-merger@google.com> 2016-02-17 18:37:52 +0000
commitef6908e2b3e6ee6514620acc338b458ade7c3640 (patch)
tree8ccc87d1c74fd914c658bf37a352013bfcd0540b /libs
parent413318311c8cc356dd7e0837ce26e937a9f4c56a (diff)
parent94b0d4e3ab023cfa03a7a4e85f3e09d3743da715 (diff)
Sanity check IMemory access versus underlying mmap
am: 94b0d4e3ab * commit '94b0d4e3ab023cfa03a7a4e85f3e09d3743da715': Sanity check IMemory access versus underlying mmap
Diffstat (limited to 'libs')
-rw-r--r--libs/binder/IMemory.cpp18
1 files changed, 15 insertions, 3 deletions
diff --git a/libs/binder/IMemory.cpp b/libs/binder/IMemory.cpp
index 07cb41a758..99df06d57d 100644
--- a/libs/binder/IMemory.cpp
+++ b/libs/binder/IMemory.cpp
@@ -26,6 +26,7 @@
#include <sys/mman.h>
#include <binder/IMemory.h>
+#include <cutils/log.h>
#include <utils/KeyedVector.h>
#include <utils/threads.h>
#include <utils/Atomic.h>
@@ -187,15 +188,26 @@ sp<IMemoryHeap> BpMemory::getMemory(ssize_t* offset, size_t* size) const
if (heap != 0) {
mHeap = interface_cast<IMemoryHeap>(heap);
if (mHeap != 0) {
- mOffset = o;
- mSize = s;
+ size_t heapSize = mHeap->getSize();
+ if (s <= heapSize
+ && o >= 0
+ && (static_cast<size_t>(o) <= heapSize - s)) {
+ mOffset = o;
+ mSize = s;
+ } else {
+ // Hm.
+ android_errorWriteWithInfoLog(0x534e4554,
+ "26877992", -1, NULL, 0);
+ mOffset = 0;
+ mSize = 0;
+ }
}
}
}
}
if (offset) *offset = mOffset;
if (size) *size = mSize;
- return mHeap;
+ return (mSize > 0) ? mHeap : 0;
}
// ---------------------------------------------------------------------------