summaryrefslogtreecommitdiff
path: root/libs/androidfw/CursorWindow.cpp
diff options
context:
space:
mode:
authorFyodor Kupolov <fkupolov@google.com>2017-02-13 18:35:12 -0800
committerFyodor Kupolov <fkupolov@google.com>2017-02-16 09:50:00 -0800
commit45e2e95c2ffeb2d978e2cce80b729ef6ada3b8d2 (patch)
tree992c98155bec887d70df51eb7b90a35a1fe564a9 /libs/androidfw/CursorWindow.cpp
parent3d52f79be4dba94f046709fabc1bfb911a670709 (diff)
Check bounds in offsetToPtr
Check whether specified offset belongs to mData. Also added a default argument bufferSize to check the end offset. Size of the ashmem descriptor can be modified between ashmem_get_size_region call and mmap. createFromParcel method was updated to check ashmem size again immediately after memory is mapped. Test: manual - using the test app from the bug Bug: 34128677 Change-Id: I3ecd1616a870ce20941ce9b20a1843d2b4295750
Diffstat (limited to 'libs/androidfw/CursorWindow.cpp')
-rw-r--r--libs/androidfw/CursorWindow.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/libs/androidfw/CursorWindow.cpp b/libs/androidfw/CursorWindow.cpp
index 166863c0d91a..5694115f61aa 100644
--- a/libs/androidfw/CursorWindow.cpp
+++ b/libs/androidfw/CursorWindow.cpp
@@ -98,9 +98,14 @@ status_t CursorWindow::createFromParcel(Parcel* parcel, CursorWindow** outCursor
if (dupAshmemFd < 0) {
result = -errno;
} else {
+ // the size of the ashmem descriptor can be modified between ashmem_get_size_region
+ // call and mmap, so we'll check again immediately after memory is mapped
void* data = ::mmap(NULL, size, PROT_READ, MAP_SHARED, dupAshmemFd, 0);
if (data == MAP_FAILED) {
result = -errno;
+ } else if (ashmem_get_size_region(dupAshmemFd) != size) {
+ ::munmap(data, size);
+ result = BAD_VALUE;
} else {
CursorWindow* window = new CursorWindow(name, dupAshmemFd,
data, size, true /*readOnly*/);