@@ -256,7 +256,7 @@ status_t Parcel::flattenBinder(const sp<IBinder>& binder) {
256256
257257 if (const auto * rpcFields = maybeRpcFields ()) {
258258 if (binder) {
259- status_t status = writeInt32 (1 ); // non-null
259+ status_t status = writeInt32 (RpcFields::TYPE_BINDER ); // non-null
260260 if (status != OK) return status;
261261 uint64_t address;
262262 // TODO(b/167966510): need to undo this if the Parcel is not sent
@@ -266,7 +266,7 @@ status_t Parcel::flattenBinder(const sp<IBinder>& binder) {
266266 status = writeUint64 (address);
267267 if (status != OK) return status;
268268 } else {
269- status_t status = writeInt32 (0 ); // null
269+ status_t status = writeInt32 (RpcFields::TYPE_BINDER_NULL ); // null
270270 if (status != OK) return status;
271271 }
272272 return finishFlattenBinder (binder);
@@ -740,6 +740,12 @@ bool Parcel::hasFileDescriptors() const
740740 return kernelFields->mHasFds ;
741741}
742742
743+ status_t Parcel::hasBinders (bool * result) const {
744+ status_t status = hasBindersInRange (0 , dataSize (), result);
745+ ALOGE_IF (status != NO_ERROR, " Error %d calling hasBindersInRange()" , status);
746+ return status;
747+ }
748+
743749std::vector<sp<IBinder>> Parcel::debugReadAllStrongBinders () const {
744750 std::vector<sp<IBinder>> ret;
745751
@@ -799,6 +805,46 @@ std::vector<int> Parcel::debugReadAllFileDescriptors() const {
799805 return ret;
800806}
801807
808+ status_t Parcel::hasBindersInRange (size_t offset, size_t len, bool * result) const {
809+ if (len > INT32_MAX || offset > INT32_MAX) {
810+ // Don't accept size_t values which may have come from an inadvertent conversion from a
811+ // negative int.
812+ return BAD_VALUE;
813+ }
814+ size_t limit;
815+ if (__builtin_add_overflow (offset, len, &limit) || limit > mDataSize ) {
816+ return BAD_VALUE;
817+ }
818+ *result = false ;
819+ if (const auto * kernelFields = maybeKernelFields ()) {
820+ #ifdef BINDER_WITH_KERNEL_IPC
821+ for (size_t i = 0 ; i < kernelFields->mObjectsSize ; i++) {
822+ size_t pos = kernelFields->mObjects [i];
823+ if (pos < offset) continue ;
824+ if (pos + sizeof (flat_binder_object) > offset + len) {
825+ if (kernelFields->mObjectsSorted ) {
826+ break ;
827+ } else {
828+ continue ;
829+ }
830+ }
831+ const flat_binder_object* flat =
832+ reinterpret_cast <const flat_binder_object*>(mData + pos);
833+ if (flat->hdr .type == BINDER_TYPE_BINDER || flat->hdr .type == BINDER_TYPE_HANDLE) {
834+ *result = true ;
835+ break ;
836+ }
837+ }
838+ #else
839+ LOG_ALWAYS_FATAL (" Binder kernel driver disabled at build time" );
840+ return INVALID_OPERATION;
841+ #endif // BINDER_WITH_KERNEL_IPC
842+ } else if (const auto * rpcFields = maybeRpcFields ()) {
843+ return INVALID_OPERATION;
844+ }
845+ return NO_ERROR;
846+ }
847+
802848status_t Parcel::hasFileDescriptorsInRange (size_t offset, size_t len, bool * result) const {
803849 if (len > INT32_MAX || offset > INT32_MAX) {
804850 // Don't accept size_t values which may have come from an inadvertent conversion from a
0 commit comments