diff options
| author | 2022-06-09 00:40:11 +0000 | |
|---|---|---|
| committer | 2022-06-09 00:40:11 +0000 | |
| commit | 7635ebd85a6a32b9afb447a39eaaf754368c2001 (patch) | |
| tree | 614c5b7b876397cc39c3c183bcf5f152cd356d59 /libs/binder/RpcState.cpp | |
| parent | 006efbeeb00e2256fa1c57bc5dc97f5c575f1925 (diff) | |
| parent | 66d083b88f69b8381944a172445e3ecd364d3718 (diff) | |
Merge "libbinder: Remove flexible array from RpcWireReply" am: c56d0ecb4f am: 66d083b88f
Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/2118587
Change-Id: Ifb3e592d55c0513a879f13c23b52430de12a7ca3
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
Diffstat (limited to 'libs/binder/RpcState.cpp')
| -rw-r--r-- | libs/binder/RpcState.cpp | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/libs/binder/RpcState.cpp b/libs/binder/RpcState.cpp index 7ec8e0738d..f16a9ab98f 100644 --- a/libs/binder/RpcState.cpp +++ b/libs/binder/RpcState.cpp @@ -563,7 +563,7 @@ status_t RpcState::transactAddress(const sp<RpcSession::RpcConnection>& connecti static void cleanup_reply_data(Parcel* p, const uint8_t* data, size_t dataSize, const binder_size_t* objects, size_t objectsCount) { (void)p; - delete[] const_cast<uint8_t*>(data - offsetof(RpcWireReply, data)); + delete[] const_cast<uint8_t*>(data); (void)dataSize; LOG_ALWAYS_FATAL_IF(objects != nullptr); LOG_ALWAYS_FATAL_IF(objectsCount != 0, "%zu objects remaining", objectsCount); @@ -585,25 +585,30 @@ status_t RpcState::waitForReply(const sp<RpcSession::RpcConnection>& connection, return status; } - CommandData data(command.bodySize); - if (!data.valid()) return NO_MEMORY; - - iovec iov{data.data(), command.bodySize}; - if (status_t status = rpcRec(connection, session, "reply body", &iov, 1); status != OK) - return status; - if (command.bodySize < sizeof(RpcWireReply)) { ALOGE("Expecting %zu but got %" PRId32 " bytes for RpcWireReply. Terminating!", sizeof(RpcWireReply), command.bodySize); (void)session->shutdownAndWait(false); return BAD_VALUE; } - RpcWireReply* rpcReply = reinterpret_cast<RpcWireReply*>(data.data()); - if (rpcReply->status != OK) return rpcReply->status; + RpcWireReply rpcReply; + CommandData data(command.bodySize - sizeof(RpcWireReply)); + if (!data.valid()) return NO_MEMORY; + + iovec iovs[]{ + {&rpcReply, sizeof(RpcWireReply)}, + {data.data(), data.size()}, + }; + if (status_t status = rpcRec(connection, session, "reply body", iovs, arraysize(iovs)); + status != OK) + return status; + if (rpcReply.status != OK) return rpcReply.status; + + uint8_t* parcelData = data.data(); + size_t parcelDataSize = data.size(); data.release(); - reply->rpcSetDataReference(session, rpcReply->data, - command.bodySize - offsetof(RpcWireReply, data), cleanup_reply_data); + reply->rpcSetDataReference(session, parcelData, parcelDataSize, cleanup_reply_data); return OK; } |