libbinder: ensure entire Parcel is the same format
Extra check in preparation for versioning work/as a guard against misuse
of this API. Note - these functions are very much like constructors, but
they can't be because Parcel is that errorprone type of object which
resets its internal state (for better or worse).
Bug: 182938972
Test: binderRpcTest
Change-Id: Ibdbe8161db9d0c8fba86f1c691c73aab49b21bc0
diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp
index 96d12ca..3f0b0df 100644
--- a/libs/binder/Parcel.cpp
+++ b/libs/binder/Parcel.cpp
@@ -555,12 +555,17 @@
}
void Parcel::markForBinder(const sp<IBinder>& binder) {
+ LOG_ALWAYS_FATAL_IF(mData != nullptr, "format must be set before data is written");
+
if (binder && binder->remoteBinder() && binder->remoteBinder()->isRpcBinder()) {
markForRpc(binder->remoteBinder()->getPrivateAccessorForId().rpcConnection());
}
}
void Parcel::markForRpc(const sp<RpcConnection>& connection) {
+ LOG_ALWAYS_FATAL_IF(mData != nullptr && mOwner == nullptr,
+ "format must be set before data is written OR on IPC data");
+
LOG_ALWAYS_FATAL_IF(connection == nullptr, "markForRpc requires connection");
mConnection = connection;
}