From d23f9500efa59d46c57db423a630b111e889a680 Mon Sep 17 00:00:00 2001 From: Jooyung Han Date: Thu, 23 Dec 2021 14:39:57 +0900 Subject: libbinder: added enforceNoDataAvail() enforceNoDataAvail() verifies that there's no bytes left to be read on the Parcel. Bug: 208509444 Test: atest binderUnitTest Test: binder_parcel_fuzzer Change-Id: I469c8778fa54f3db27f00a9df8db668a0c4c76bc --- libs/binder/Parcel.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'libs/binder/Parcel.cpp') diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp index 7027a4b0a3..6fb189cd70 100644 --- a/libs/binder/Parcel.cpp +++ b/libs/binder/Parcel.cpp @@ -739,6 +739,17 @@ bool Parcel::enforceInterface(const char16_t* interface, } } +binder::Status Parcel::enforceNoDataAvail() const { + const auto n = dataAvail(); + if (n == 0) { + return binder::Status::ok(); + } + return binder::Status:: + fromExceptionCode(binder::Status::Exception::EX_BAD_PARCELABLE, + String8::format("Parcel data not fully consumed, unread size: %zu", + n)); +} + size_t Parcel::objectsCount() const { return mObjectsSize; -- cgit v1.2.3-59-g8ed1b