diff options
| author | 2020-12-23 02:33:02 +0000 | |
|---|---|---|
| committer | 2020-12-23 02:34:35 +0000 | |
| commit | 07463103f75bdc747ef2bb9be100fba5ed58adca (patch) | |
| tree | f4ee7c1f7e74eb799f72a8e8f85b08e63f43b4b6 | |
| parent | 64618017e4a2bcbf3f1d3928a3c2a0adecf3cf56 (diff) | |
libbinder_ndk: log on null non-@nullable fd/binder
b/c the NDK backend C++ types can actually contain the null value, it's
not clear from the type system alone that these cannot be null or why.
Bug: 176177197
Test: with `atest CtsNdkBinderTestCases`
12-23 02:18:12.891 29957 29979 E android.binder.cts: Passing null binder
object as non-@nullable AIDL IBinder
12-23 02:18:12.902 29957 29979 E android.binder.cts: Passing -1 file
descriptor as non-@nullable AIDL ParcelFileDescriptor
12-23 02:18:13.149 29957 29979 E android.binder.cts: Passing null binder
object as non-@nullable AIDL IBinder
12-23 02:18:13.160 29957 29979 E android.binder.cts: Passing -1 file
descriptor as non-@nullable AIDL ParcelFileDescriptor
12-23 02:18:13.282 29957 29979 E android.binder.cts: Passing null binder
object as non-@nullable AIDL IBinder
12-23 02:18:13.295 29957 29979 E android.binder.cts: Passing -1 file
descriptor as non-@nullable AIDL ParcelFileDescriptor
12-23 02:18:13.452 29957 29979 E android.binder.cts: Passing null binder
object as non-@nullable AIDL IBinder
12-23 02:18:13.465 29957 29979 E android.binder.cts: Passing -1 file
descriptor as non-@nullable AIDL ParcelFileDescriptor
12-23 02:18:13.621 29957 29979 E android.binder.cts: Passing null binder
object as non-@nullable AIDL IBinder
12-23 02:18:13.634 29957 29979 E android.binder.cts: Passing -1 file
descriptor as non-@nullable AIDL ParcelFileDescriptor
Change-Id: Ic855aa85d95724e82c46e941b442ff6cbba39e77
3 files changed, 42 insertions, 8 deletions
diff --git a/libs/binder/ndk/include_cpp/android/binder_auto_utils.h b/libs/binder/ndk/include_cpp/android/binder_auto_utils.h index c44a24ba04..53871f28a2 100644 --- a/libs/binder/ndk/include_cpp/android/binder_auto_utils.h +++ b/libs/binder/ndk/include_cpp/android/binder_auto_utils.h @@ -27,19 +27,12 @@ #pragma once #include <android/binder_ibinder.h> +#include <android/binder_internal_logging.h> #include <android/binder_parcel.h> #include <android/binder_status.h> #include <assert.h> -// defined differently by liblog -#pragma push_macro("LOG_PRI") -#ifdef LOG_PRI -#undef LOG_PRI -#endif -#include <syslog.h> -#pragma pop_macro("LOG_PRI") - #include <unistd.h> #include <cstddef> #include <string> diff --git a/libs/binder/ndk/include_cpp/android/binder_internal_logging.h b/libs/binder/ndk/include_cpp/android/binder_internal_logging.h new file mode 100644 index 0000000000..88c6443f71 --- /dev/null +++ b/libs/binder/ndk/include_cpp/android/binder_internal_logging.h @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup NdkBinder + * @{ + */ + +/** + * @file binder_internal_logging.h + * @brief This provides the ability to use syslog from binder headers, since + * other logging functionality might be inaccessable. + */ + +#pragma once + +// defined differently by liblog +#pragma push_macro("LOG_PRI") +#ifdef LOG_PRI +#undef LOG_PRI +#endif +#include <syslog.h> +#pragma pop_macro("LOG_PRI") + +/** @} */ diff --git a/libs/binder/ndk/include_cpp/android/binder_parcel_utils.h b/libs/binder/ndk/include_cpp/android/binder_parcel_utils.h index 054aebeb50..83190aa56e 100644 --- a/libs/binder/ndk/include_cpp/android/binder_parcel_utils.h +++ b/libs/binder/ndk/include_cpp/android/binder_parcel_utils.h @@ -27,6 +27,7 @@ #pragma once #include <android/binder_auto_utils.h> +#include <android/binder_internal_logging.h> #include <android/binder_parcel.h> #include <optional> @@ -179,6 +180,7 @@ static inline binder_status_t AParcel_readNullableStrongBinder(const AParcel* pa static inline binder_status_t AParcel_writeRequiredStrongBinder(AParcel* parcel, const SpAIBinder& binder) { if (binder.get() == nullptr) { + syslog(LOG_ERR, "Passing null binder object as non-@nullable AIDL IBinder"); return STATUS_UNEXPECTED_NULL; } return AParcel_writeStrongBinder(parcel, binder.get()); @@ -228,6 +230,7 @@ static inline binder_status_t AParcel_readNullableParcelFileDescriptor(const APa static inline binder_status_t AParcel_writeRequiredParcelFileDescriptor( AParcel* parcel, const ScopedFileDescriptor& fd) { if (fd.get() < 0) { + syslog(LOG_ERR, "Passing -1 file descriptor as non-@nullable AIDL ParcelFileDescriptor"); return STATUS_UNEXPECTED_NULL; } return AParcel_writeParcelFileDescriptor(parcel, fd.get()); |