Loading libs/binder/Parcel.cpp +6 −3 Original line number Diff line number Diff line Loading @@ -614,11 +614,14 @@ status_t Parcel::appendFrom(const Parcel* parcel, size_t offset, size_t len) { if (status_t status = readInt32(&fdIndex); status != OK) { return status; } const auto& oldFd = otherRpcFields->mFds->at(fdIndex); int oldFd = toRawFd(otherRpcFields->mFds->at(fdIndex)); // To match kernel binder behavior, we always dup, even if the // FD was unowned in the source parcel. rpcFields->mFds->emplace_back( base::unique_fd(fcntl(toRawFd(oldFd), F_DUPFD_CLOEXEC, 0))); int newFd = -1; if (status_t status = dupFileDescriptor(oldFd, &newFd); status != OK) { ALOGW("Failed to duplicate file descriptor %d: %s", oldFd, strerror(-status)); } rpcFields->mFds->emplace_back(base::unique_fd(newFd)); // Fixup the index in the data. mDataPos = newDataPos + 4; if (status_t status = writeInt32(rpcFields->mFds->size() - 1); status != OK) { Loading libs/binder/ndk/include_cpp/android/binder_to_string.h +3 −5 Original line number Diff line number Diff line Loading @@ -160,7 +160,7 @@ class ToEmptyString { template <typename _T> std::string ToString(const _T& t) { if constexpr (details::ToEmptyString<_T>::value) { return "<unimplemented>"; return ""; } else if constexpr (std::is_same_v<bool, _T>) { return t ? "true" : "false"; } else if constexpr (std::is_same_v<char16_t, _T>) { Loading @@ -176,11 +176,9 @@ std::string ToString(const _T& t) { return t; #ifdef HAS_NDK_INTERFACE } else if constexpr (std::is_same_v<::ndk::SpAIBinder, _T>) { std::stringstream ss; ss << "binder:" << std::hex << t.get(); return ss.str(); return (t.get() == nullptr) ? "(null)" : ""; } else if constexpr (std::is_same_v<::ndk::ScopedFileDescriptor, _T>) { return "fd:" + std::to_string(t.get()); return (t.get() == -1) ? "(null)" : ""; #endif #ifdef HAS_STRING16 } else if constexpr (std::is_same_v<String16, _T>) { Loading libs/binder/tests/binderRpcTest.cpp +27 −0 Original line number Diff line number Diff line Loading @@ -913,6 +913,33 @@ TEST_P(BinderRpc, SendTooManyFiles) { EXPECT_EQ(status.transactionError(), BAD_VALUE) << status; } TEST_P(BinderRpc, AppendInvalidFd) { auto proc = createRpcTestSocketServerProcess({ .clientFileDescriptorTransportMode = RpcSession::FileDescriptorTransportMode::UNIX, .serverSupportedFileDescriptorTransportModes = {RpcSession::FileDescriptorTransportMode::UNIX}, }); int badFd = fcntl(STDERR_FILENO, F_DUPFD_CLOEXEC, 0); ASSERT_NE(badFd, -1); // Close the file descriptor so it becomes invalid for dup close(badFd); Parcel p1; p1.markForBinder(proc.rootBinder); p1.writeInt32(3); EXPECT_EQ(OK, p1.writeFileDescriptor(badFd, false)); Parcel pRaw; pRaw.markForBinder(proc.rootBinder); EXPECT_EQ(OK, pRaw.appendFrom(&p1, 0, p1.dataSize())); pRaw.setDataPosition(0); EXPECT_EQ(3, pRaw.readInt32()); ASSERT_EQ(-1, pRaw.readFileDescriptor()); } TEST_P(BinderRpc, WorksWithLibbinderNdkPing) { if constexpr (!kEnableSharedLibs) { GTEST_SKIP() << "Test disabled because Binder was built as a static library"; Loading libs/binder/trusty/include/log/log.h +4 −0 Original line number Diff line number Diff line Loading @@ -120,3 +120,7 @@ static inline void __ignore_va_args__(...) {} do { \ TLOGE("android_errorWriteLog: tag:%x subTag:%s\n", tag, subTag); \ } while (0) extern "C" inline void __assert(const char* file, int line, const char* str) { LOG_ALWAYS_FATAL("%s:%d: assertion \"%s\" failed", file, line, str); } libs/gui/fuzzer/Android.bp +0 −1 Original line number Diff line number Diff line Loading @@ -62,7 +62,6 @@ cc_defaults { "libutils", "libnativewindow", "libvndksupport", "libbufferhubqueue", ], header_libs: [ "libdvr_headers", Loading Loading
libs/binder/Parcel.cpp +6 −3 Original line number Diff line number Diff line Loading @@ -614,11 +614,14 @@ status_t Parcel::appendFrom(const Parcel* parcel, size_t offset, size_t len) { if (status_t status = readInt32(&fdIndex); status != OK) { return status; } const auto& oldFd = otherRpcFields->mFds->at(fdIndex); int oldFd = toRawFd(otherRpcFields->mFds->at(fdIndex)); // To match kernel binder behavior, we always dup, even if the // FD was unowned in the source parcel. rpcFields->mFds->emplace_back( base::unique_fd(fcntl(toRawFd(oldFd), F_DUPFD_CLOEXEC, 0))); int newFd = -1; if (status_t status = dupFileDescriptor(oldFd, &newFd); status != OK) { ALOGW("Failed to duplicate file descriptor %d: %s", oldFd, strerror(-status)); } rpcFields->mFds->emplace_back(base::unique_fd(newFd)); // Fixup the index in the data. mDataPos = newDataPos + 4; if (status_t status = writeInt32(rpcFields->mFds->size() - 1); status != OK) { Loading
libs/binder/ndk/include_cpp/android/binder_to_string.h +3 −5 Original line number Diff line number Diff line Loading @@ -160,7 +160,7 @@ class ToEmptyString { template <typename _T> std::string ToString(const _T& t) { if constexpr (details::ToEmptyString<_T>::value) { return "<unimplemented>"; return ""; } else if constexpr (std::is_same_v<bool, _T>) { return t ? "true" : "false"; } else if constexpr (std::is_same_v<char16_t, _T>) { Loading @@ -176,11 +176,9 @@ std::string ToString(const _T& t) { return t; #ifdef HAS_NDK_INTERFACE } else if constexpr (std::is_same_v<::ndk::SpAIBinder, _T>) { std::stringstream ss; ss << "binder:" << std::hex << t.get(); return ss.str(); return (t.get() == nullptr) ? "(null)" : ""; } else if constexpr (std::is_same_v<::ndk::ScopedFileDescriptor, _T>) { return "fd:" + std::to_string(t.get()); return (t.get() == -1) ? "(null)" : ""; #endif #ifdef HAS_STRING16 } else if constexpr (std::is_same_v<String16, _T>) { Loading
libs/binder/tests/binderRpcTest.cpp +27 −0 Original line number Diff line number Diff line Loading @@ -913,6 +913,33 @@ TEST_P(BinderRpc, SendTooManyFiles) { EXPECT_EQ(status.transactionError(), BAD_VALUE) << status; } TEST_P(BinderRpc, AppendInvalidFd) { auto proc = createRpcTestSocketServerProcess({ .clientFileDescriptorTransportMode = RpcSession::FileDescriptorTransportMode::UNIX, .serverSupportedFileDescriptorTransportModes = {RpcSession::FileDescriptorTransportMode::UNIX}, }); int badFd = fcntl(STDERR_FILENO, F_DUPFD_CLOEXEC, 0); ASSERT_NE(badFd, -1); // Close the file descriptor so it becomes invalid for dup close(badFd); Parcel p1; p1.markForBinder(proc.rootBinder); p1.writeInt32(3); EXPECT_EQ(OK, p1.writeFileDescriptor(badFd, false)); Parcel pRaw; pRaw.markForBinder(proc.rootBinder); EXPECT_EQ(OK, pRaw.appendFrom(&p1, 0, p1.dataSize())); pRaw.setDataPosition(0); EXPECT_EQ(3, pRaw.readInt32()); ASSERT_EQ(-1, pRaw.readFileDescriptor()); } TEST_P(BinderRpc, WorksWithLibbinderNdkPing) { if constexpr (!kEnableSharedLibs) { GTEST_SKIP() << "Test disabled because Binder was built as a static library"; Loading
libs/binder/trusty/include/log/log.h +4 −0 Original line number Diff line number Diff line Loading @@ -120,3 +120,7 @@ static inline void __ignore_va_args__(...) {} do { \ TLOGE("android_errorWriteLog: tag:%x subTag:%s\n", tag, subTag); \ } while (0) extern "C" inline void __assert(const char* file, int line, const char* str) { LOG_ALWAYS_FATAL("%s:%d: assertion \"%s\" failed", file, line, str); }
libs/gui/fuzzer/Android.bp +0 −1 Original line number Diff line number Diff line Loading @@ -62,7 +62,6 @@ cc_defaults { "libutils", "libnativewindow", "libvndksupport", "libbufferhubqueue", ], header_libs: [ "libdvr_headers", Loading