From 3281437213dd9d8dce1e12f9141b71104f198738 Mon Sep 17 00:00:00 2001 From: Andrei Homescu Date: Thu, 20 Aug 2020 15:36:08 -0700 Subject: Changes to UNEXPECTED_NULL handling in libbinder_rs. Two changes related to UNEXPECTED_NULL in libbinder_rs: 1) Return UNEXPECTED_NULL from Deserialize for SpIBinder instead of panicking 2) Convert UNEXPECTED_NULL status codes to NULL_POINTER exceptions, for compatibility with C++ and Java services. Test: atest aidl_integration_test with 1406447 applied Change-Id: I2e7cc92b2e1cf08a35968f675827d7d917144110 --- libs/binder/rust/src/binder.rs | 12 +++++++++++- libs/binder/rust/src/proxy.rs | 5 ++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/libs/binder/rust/src/binder.rs b/libs/binder/rust/src/binder.rs index 6bf9cd5c4c..6186b88eed 100644 --- a/libs/binder/rust/src/binder.rs +++ b/libs/binder/rust/src/binder.rs @@ -529,7 +529,17 @@ macro_rules! declare_binder_interface { } fn on_transact(&self, code: $crate::TransactionCode, data: &$crate::Parcel, reply: &mut $crate::Parcel) -> $crate::Result<()> { - $on_transact(&*self.0, code, data, reply) + match $on_transact(&*self.0, code, data, reply) { + // The C++ backend converts UNEXPECTED_NULL into an exception + Err($crate::StatusCode::UNEXPECTED_NULL) => { + let status = $crate::Status::new_exception( + $crate::ExceptionCode::NULL_POINTER, + None, + ); + reply.write(&status) + }, + result => result + } } fn get_class() -> $crate::InterfaceClass { diff --git a/libs/binder/rust/src/proxy.rs b/libs/binder/rust/src/proxy.rs index 5602c9688c..2997da3226 100644 --- a/libs/binder/rust/src/proxy.rs +++ b/libs/binder/rust/src/proxy.rs @@ -346,7 +346,10 @@ impl SerializeArray for Option<&SpIBinder> {} impl Deserialize for SpIBinder { fn deserialize(parcel: &Parcel) -> Result { - parcel.read_binder().transpose().unwrap() + parcel + .read_binder() + .transpose() + .unwrap_or(Err(StatusCode::UNEXPECTED_NULL)) } } -- cgit v1.2.3-59-g8ed1b