Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 07463103 authored by Steven Moreland's avatar Steven Moreland
Browse files

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
parent 64618017
Loading
Loading
Loading
Loading
+1 −8
Original line number Original line Diff line number Diff line
@@ -27,19 +27,12 @@
#pragma once
#pragma once


#include <android/binder_ibinder.h>
#include <android/binder_ibinder.h>
#include <android/binder_internal_logging.h>
#include <android/binder_parcel.h>
#include <android/binder_parcel.h>
#include <android/binder_status.h>
#include <android/binder_status.h>


#include <assert.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 <unistd.h>
#include <cstddef>
#include <cstddef>
#include <string>
#include <string>
+38 −0
Original line number Original line Diff line number Diff line
/*
 * 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")

/** @} */
+3 −0
Original line number Original line Diff line number Diff line
@@ -27,6 +27,7 @@
#pragma once
#pragma once


#include <android/binder_auto_utils.h>
#include <android/binder_auto_utils.h>
#include <android/binder_internal_logging.h>
#include <android/binder_parcel.h>
#include <android/binder_parcel.h>


#include <optional>
#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,
static inline binder_status_t AParcel_writeRequiredStrongBinder(AParcel* parcel,
                                                                const SpAIBinder& binder) {
                                                                const SpAIBinder& binder) {
    if (binder.get() == nullptr) {
    if (binder.get() == nullptr) {
        syslog(LOG_ERR, "Passing null binder object as non-@nullable AIDL IBinder");
        return STATUS_UNEXPECTED_NULL;
        return STATUS_UNEXPECTED_NULL;
    }
    }
    return AParcel_writeStrongBinder(parcel, binder.get());
    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(
static inline binder_status_t AParcel_writeRequiredParcelFileDescriptor(
        AParcel* parcel, const ScopedFileDescriptor& fd) {
        AParcel* parcel, const ScopedFileDescriptor& fd) {
    if (fd.get() < 0) {
    if (fd.get() < 0) {
        syslog(LOG_ERR, "Passing -1 file descriptor as non-@nullable AIDL ParcelFileDescriptor");
        return STATUS_UNEXPECTED_NULL;
        return STATUS_UNEXPECTED_NULL;
    }
    }
    return AParcel_writeParcelFileDescriptor(parcel, fd.get());
    return AParcel_writeParcelFileDescriptor(parcel, fd.get());