diff options
-rw-r--r-- | libs/binder/RpcServer.cpp | 12 | ||||
-rw-r--r-- | libs/binder/RpcSession.cpp | 6 | ||||
-rw-r--r-- | libs/binder/RpcState.cpp | 5 | ||||
-rw-r--r-- | libs/binder/Utils.cpp | 19 | ||||
-rw-r--r-- | libs/binder/Utils.h | 6 | ||||
-rw-r--r-- | libs/binder/tests/binderClearBufTest.cpp | 5 | ||||
-rw-r--r-- | libs/binder/tests/binderRpcWireProtocolTest.cpp | 4 | ||||
-rw-r--r-- | libs/binder/tests/parcel_fuzzer/binder.cpp | 5 | ||||
-rw-r--r-- | libs/binder/tests/parcel_fuzzer/hwbinder.cpp | 5 | ||||
-rw-r--r-- | libs/binder/tests/parcel_fuzzer/include_random_parcel_seeds/fuzzseeds/random_parcel_seeds.h | 2 | ||||
-rw-r--r-- | libs/binder/tests/parcel_fuzzer/main.cpp | 5 |
11 files changed, 48 insertions, 26 deletions
diff --git a/libs/binder/RpcServer.cpp b/libs/binder/RpcServer.cpp index 55fc16de45..9622313699 100644 --- a/libs/binder/RpcServer.cpp +++ b/libs/binder/RpcServer.cpp @@ -24,7 +24,6 @@ #include <thread> #include <vector> -#include <android-base/hex.h> #include <android-base/scopeguard.h> #include <binder/Parcel.h> #include <binder/RpcServer.h> @@ -484,7 +483,7 @@ void RpcServer::establishConnection( // don't block if there is some entropy issue if (tries++ > 5) { ALOGE("Cannot find new address: %s", - base::HexString(sessionId.data(), sessionId.size()).c_str()); + HexString(sessionId.data(), sessionId.size()).c_str()); return; } @@ -536,7 +535,7 @@ void RpcServer::establishConnection( auto it = server->mSessions.find(sessionId); if (it == server->mSessions.end()) { ALOGE("Cannot add thread, no record of session with ID %s", - base::HexString(sessionId.data(), sessionId.size()).c_str()); + HexString(sessionId.data(), sessionId.size()).c_str()); return; } session = it->second; @@ -610,15 +609,14 @@ status_t RpcServer::setupRawSocketServer(unique_fd socket_fd) { void RpcServer::onSessionAllIncomingThreadsEnded(const sp<RpcSession>& session) { const std::vector<uint8_t>& id = session->mId; LOG_ALWAYS_FATAL_IF(id.empty(), "Server sessions must be initialized with ID"); - LOG_RPC_DETAIL("Dropping session with address %s", - base::HexString(id.data(), id.size()).c_str()); + LOG_RPC_DETAIL("Dropping session with address %s", HexString(id.data(), id.size()).c_str()); RpcMutexLockGuard _l(mLock); auto it = mSessions.find(id); LOG_ALWAYS_FATAL_IF(it == mSessions.end(), "Bad state, unknown session id %s", - base::HexString(id.data(), id.size()).c_str()); + HexString(id.data(), id.size()).c_str()); LOG_ALWAYS_FATAL_IF(it->second != session, "Bad state, session has id mismatch %s", - base::HexString(id.data(), id.size()).c_str()); + HexString(id.data(), id.size()).c_str()); (void)mSessions.erase(it); } diff --git a/libs/binder/RpcSession.cpp b/libs/binder/RpcSession.cpp index c3dee1650e..edac56ba3b 100644 --- a/libs/binder/RpcSession.cpp +++ b/libs/binder/RpcSession.cpp @@ -26,7 +26,6 @@ #include <string_view> -#include <android-base/hex.h> #include <android-base/macros.h> #include <android-base/scopeguard.h> #include <binder/BpBinder.h> @@ -310,8 +309,7 @@ status_t RpcSession::readId() { status = state()->getSessionId(connection.get(), sp<RpcSession>::fromExisting(this), &mId); if (status != OK) return status; - LOG_RPC_DETAIL("RpcSession %p has id %s", this, - base::HexString(mId.data(), mId.size()).c_str()); + LOG_RPC_DETAIL("RpcSession %p has id %s", this, HexString(mId.data(), mId.size()).c_str()); return OK; } @@ -709,7 +707,7 @@ status_t RpcSession::initAndAddConnection(RpcTransportFd fd, const std::vector<u std::nullopt, nullptr); if (sendSessionIdStatus != OK) { ALOGE("Could not write session ID ('%s') to socket: %s", - base::HexString(sessionId.data(), sessionId.size()).c_str(), + HexString(sessionId.data(), sessionId.size()).c_str(), statusToString(sendSessionIdStatus).c_str()); return sendSessionIdStatus; } diff --git a/libs/binder/RpcState.cpp b/libs/binder/RpcState.cpp index bac2808b26..cf14bce705 100644 --- a/libs/binder/RpcState.cpp +++ b/libs/binder/RpcState.cpp @@ -18,7 +18,6 @@ #include "RpcState.h" -#include <android-base/hex.h> #include <android-base/macros.h> #include <android-base/scopeguard.h> #include <android-base/stringprintf.h> @@ -363,7 +362,7 @@ status_t RpcState::rpcSend( for (int i = 0; i < niovs; i++) { LOG_RPC_DETAIL("Sending %s (part %d of %d) on RpcTransport %p: %s", what, i + 1, niovs, connection->rpcTransport.get(), - android::base::HexString(iovs[i].iov_base, iovs[i].iov_len).c_str()); + HexString(iovs[i].iov_base, iovs[i].iov_len).c_str()); } if (status_t status = @@ -398,7 +397,7 @@ status_t RpcState::rpcRec( for (int i = 0; i < niovs; i++) { LOG_RPC_DETAIL("Received %s (part %d of %d) on RpcTransport %p: %s", what, i + 1, niovs, connection->rpcTransport.get(), - android::base::HexString(iovs[i].iov_base, iovs[i].iov_len).c_str()); + HexString(iovs[i].iov_base, iovs[i].iov_len).c_str()); } return OK; } diff --git a/libs/binder/Utils.cpp b/libs/binder/Utils.cpp index 0314b0fea7..47fd17dcb1 100644 --- a/libs/binder/Utils.cpp +++ b/libs/binder/Utils.cpp @@ -16,6 +16,7 @@ #include "Utils.h" +#include <android-base/logging.h> #include <string.h> namespace android { @@ -24,4 +25,22 @@ void zeroMemory(uint8_t* data, size_t size) { memset(data, 0, size); } +std::string HexString(const void* bytes, size_t len) { + CHECK(bytes != nullptr || len == 0) << bytes << " " << len; + + // b/132916539: Doing this the 'C way', std::setfill triggers ubsan implicit conversion + const uint8_t* bytes8 = static_cast<const uint8_t*>(bytes); + const char chars[] = "0123456789abcdef"; + std::string result; + result.resize(len * 2); + + for (size_t i = 0; i < len; i++) { + const auto c = bytes8[i]; + result[2 * i] = chars[c >> 4]; + result[2 * i + 1] = chars[c & 0xf]; + } + + return result; +} + } // namespace android diff --git a/libs/binder/Utils.h b/libs/binder/Utils.h index e04199c75a..dd632c0b26 100644 --- a/libs/binder/Utils.h +++ b/libs/binder/Utils.h @@ -70,4 +70,10 @@ struct Span { } }; +// Converts binary data into a hexString. +// +// Hex values are printed in order, e.g. 0xDEAD will result in 'adde' because +// Android is little-endian. +std::string HexString(const void* bytes, size_t len); + } // namespace android diff --git a/libs/binder/tests/binderClearBufTest.cpp b/libs/binder/tests/binderClearBufTest.cpp index 3ea5b553bc..e43ee5fcf5 100644 --- a/libs/binder/tests/binderClearBufTest.cpp +++ b/libs/binder/tests/binderClearBufTest.cpp @@ -14,7 +14,6 @@ * limitations under the License. */ -#include <android-base/hex.h> #include <android-base/logging.h> #include <binder/Binder.h> #include <binder/IBinder.h> @@ -24,6 +23,8 @@ #include <binder/Stability.h> #include <gtest/gtest.h> +#include "../Utils.h" + #include <sys/prctl.h> #include <thread> @@ -68,7 +69,7 @@ class FooBar : public BBinder { lastReply = reply.data(); lastReplySize = reply.dataSize(); } - *outBuffer = android::base::HexString(lastReply, lastReplySize); + *outBuffer = android::HexString(lastReply, lastReplySize); return result; } }; diff --git a/libs/binder/tests/binderRpcWireProtocolTest.cpp b/libs/binder/tests/binderRpcWireProtocolTest.cpp index 642cea440d..d0ce37d952 100644 --- a/libs/binder/tests/binderRpcWireProtocolTest.cpp +++ b/libs/binder/tests/binderRpcWireProtocolTest.cpp @@ -14,7 +14,6 @@ * limitations under the License. */ -#include <android-base/hex.h> #include <android-base/logging.h> #include <android-base/macros.h> #include <android-base/properties.h> @@ -25,6 +24,7 @@ #include <gtest/gtest.h> #include "../Debug.h" +#include "../Utils.h" namespace android { @@ -176,7 +176,7 @@ static std::string buildRepr(uint32_t version) { setParcelForRpc(&p, version); kFillFuns[i](&p); - result += base::HexString(p.data(), p.dataSize()); + result += HexString(p.data(), p.dataSize()); } return result; } diff --git a/libs/binder/tests/parcel_fuzzer/binder.cpp b/libs/binder/tests/parcel_fuzzer/binder.cpp index 46d387ce86..416ffad466 100644 --- a/libs/binder/tests/parcel_fuzzer/binder.cpp +++ b/libs/binder/tests/parcel_fuzzer/binder.cpp @@ -21,14 +21,15 @@ #include "parcelables/SingleDataParcelable.h" #include "util.h" -#include <android-base/hex.h> #include <android/os/IServiceManager.h> #include <binder/ParcelableHolder.h> #include <binder/PersistableBundle.h> #include <binder/Status.h> +#include "../../Utils.h" + using ::android::status_t; -using ::android::base::HexString; +using ::android::HexString; enum ByteEnum : int8_t {}; enum IntEnum : int32_t {}; diff --git a/libs/binder/tests/parcel_fuzzer/hwbinder.cpp b/libs/binder/tests/parcel_fuzzer/hwbinder.cpp index 438e8ae9b2..cdc8bccf0c 100644 --- a/libs/binder/tests/parcel_fuzzer/hwbinder.cpp +++ b/libs/binder/tests/parcel_fuzzer/hwbinder.cpp @@ -18,12 +18,13 @@ #include "hwbinder.h" #include "util.h" -#include <android-base/hex.h> #include <android-base/logging.h> #include <hwbinder/Parcel.h> +#include "../../Utils.h" + using ::android::status_t; -using ::android::base::HexString; +using ::android::HexString; // TODO: support scatter-gather types diff --git a/libs/binder/tests/parcel_fuzzer/include_random_parcel_seeds/fuzzseeds/random_parcel_seeds.h b/libs/binder/tests/parcel_fuzzer/include_random_parcel_seeds/fuzzseeds/random_parcel_seeds.h index 5755239c8b..071250ddf1 100644 --- a/libs/binder/tests/parcel_fuzzer/include_random_parcel_seeds/fuzzseeds/random_parcel_seeds.h +++ b/libs/binder/tests/parcel_fuzzer/include_random_parcel_seeds/fuzzseeds/random_parcel_seeds.h @@ -15,7 +15,6 @@ */ #include <android-base/file.h> -#include <android-base/hex.h> #include <android-base/logging.h> #include <binder/Binder.h> @@ -27,7 +26,6 @@ #include <vector> using android::Parcel; -using android::base::HexString; using std::vector; namespace android { diff --git a/libs/binder/tests/parcel_fuzzer/main.cpp b/libs/binder/tests/parcel_fuzzer/main.cpp index bef4ab6e99..5b1e9eac23 100644 --- a/libs/binder/tests/parcel_fuzzer/main.cpp +++ b/libs/binder/tests/parcel_fuzzer/main.cpp @@ -22,7 +22,6 @@ #include <iostream> -#include <android-base/hex.h> #include <android-base/logging.h> #include <android/binder_auto_utils.h> #include <android/binder_libbinder.h> @@ -34,10 +33,12 @@ #include <sys/resource.h> #include <sys/time.h> +#include "../../Utils.h" + using android::fillRandomParcel; using android::RandomParcelOptions; using android::sp; -using android::base::HexString; +using android::HexString; void fillRandomParcel(::android::hardware::Parcel* p, FuzzedDataProvider&& provider, RandomParcelOptions* options) { |