From abdfc248f3988ada1508338287acfd06420f649f Mon Sep 17 00:00:00 2001 From: Josh Gao Date: Fri, 7 Sep 2018 12:44:40 -0700 Subject: [PATCH] libziparchive: encode type in fdsan owner tag. Test: debuggerd `pidof system_server` | grep " fd " Change-Id: I05577adb94cf58b549aa0af03b42653e345bcd11 --- libziparchive/zip_archive.cc | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/libziparchive/zip_archive.cc b/libziparchive/zip_archive.cc index add6e14cb..fb3313be1 100644 --- a/libziparchive/zip_archive.cc +++ b/libziparchive/zip_archive.cc @@ -170,6 +170,13 @@ static int32_t AddToHash(ZipString* hash_table, const uint64_t hash_table_size, return 0; } +#if defined(__BIONIC__) +uint64_t GetOwnerTag(const ZipArchive* archive) { + return android_fdsan_create_owner_tag(ANDROID_FDSAN_OWNER_TYPE_ZIPARCHIVE, + reinterpret_cast(archive)); +} +#endif + ZipArchive::ZipArchive(const int fd, bool assume_ownership) : mapped_zip(fd), close_file(assume_ownership), @@ -181,7 +188,7 @@ ZipArchive::ZipArchive(const int fd, bool assume_ownership) hash_table(nullptr) { #if defined(__BIONIC__) if (assume_ownership) { - android_fdsan_exchange_owner_tag(fd, 0, reinterpret_cast(this)); + android_fdsan_exchange_owner_tag(fd, 0, GetOwnerTag(this)); } #endif } @@ -199,7 +206,7 @@ ZipArchive::ZipArchive(void* address, size_t length) ZipArchive::~ZipArchive() { if (close_file && mapped_zip.GetFileDescriptor() >= 0) { #if defined(__BIONIC__) - android_fdsan_close_with_tag(mapped_zip.GetFileDescriptor(), reinterpret_cast(this)); + android_fdsan_close_with_tag(mapped_zip.GetFileDescriptor(), GetOwnerTag(this)); #else close(mapped_zip.GetFileDescriptor()); #endif