Skip to content

Commit 072f129

Browse files
Christopher Tateandi34
authored andcommitted
Sanity check IMemory access versus underlying mmap
Bug 26877992 Change-Id: Ibbf4b1061e4675e4e96bc944a865b53eaf6984fe (cherry picked from commit 94b0d4e)
1 parent 04ee44c commit 072f129

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

libs/binder/IMemory.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <sys/mman.h>
2727

2828
#include <binder/IMemory.h>
29+
#include <cutils/log.h>
2930
#include <utils/KeyedVector.h>
3031
#include <utils/threads.h>
3132
#include <utils/Atomic.h>
@@ -187,15 +188,26 @@ sp<IMemoryHeap> BpMemory::getMemory(ssize_t* offset, size_t* size) const
187188
if (heap != 0) {
188189
mHeap = interface_cast<IMemoryHeap>(heap);
189190
if (mHeap != 0) {
190-
mOffset = o;
191-
mSize = s;
191+
size_t heapSize = mHeap->getSize();
192+
if (s <= heapSize
193+
&& o >= 0
194+
&& (static_cast<size_t>(o) <= heapSize - s)) {
195+
mOffset = o;
196+
mSize = s;
197+
} else {
198+
// Hm.
199+
android_errorWriteWithInfoLog(0x534e4554,
200+
"26877992", -1, NULL, 0);
201+
mOffset = 0;
202+
mSize = 0;
203+
}
192204
}
193205
}
194206
}
195207
}
196208
if (offset) *offset = mOffset;
197209
if (size) *size = mSize;
198-
return mHeap;
210+
return (mSize > 0) ? mHeap : 0;
199211
}
200212

201213
// ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)