From 0c5f923dd68d31482741ca4b44bbec80eef2fe9d Mon Sep 17 00:00:00 2001 From: Stephen Crane Date: Fri, 17 Jun 2022 11:48:05 -0700 Subject: libbinder_rs: Handle empty args list for dump transactions Previously we expected the args pointer passed to the handler for dump transactions to be non-null. If there are no arguments this pointer may be null and we should pass an empty args list instead of erroring out. Bug: 232887857 Test: atest -p frameworks/native/libs/binder Test: cts -m CtsSecurityTestCases -t android.security.cts.ServicePermissionsTest#testDumpProtected Change-Id: If2b08c688a374913ef0913749efc72db07e7776f --- libs/binder/rust/src/native.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/libs/binder/rust/src/native.rs b/libs/binder/rust/src/native.rs index b7c7ae4b54..3edeebf892 100644 --- a/libs/binder/rust/src/native.rs +++ b/libs/binder/rust/src/native.rs @@ -335,11 +335,16 @@ impl InterfaceClassMethods for Binder { // We don't own this file, so we need to be careful not to drop it. let file = ManuallyDrop::new(File::from_raw_fd(fd)); - if args.is_null() { + if args.is_null() && num_args != 0 { return StatusCode::UNEXPECTED_NULL as status_t; } - let args = slice::from_raw_parts(args, num_args as usize); - let args: Vec<_> = args.iter().map(|s| CStr::from_ptr(*s)).collect(); + + let args = if args.is_null() || num_args == 0 { + vec![] + } else { + slice::from_raw_parts(args, num_args as usize) + .iter().map(|s| CStr::from_ptr(*s)).collect() + }; let object = sys::AIBinder_getUserData(binder); let binder: &T = &*(object as *const T); -- cgit v1.2.3-59-g8ed1b