Fix various not so benign fdsan errors.
Bug: http://b/113558485
Test: art/test.py --target --gtest
Change-Id: Ic376ec33fff30a239d978e40b0c48966c6d0a9c2
diff --git a/libdexfile/dex/art_dex_file_loader.cc b/libdexfile/dex/art_dex_file_loader.cc
index eb7d3d3..4f73967 100644
--- a/libdexfile/dex/art_dex_file_loader.cc
+++ b/libdexfile/dex/art_dex_file_loader.cc
@@ -95,7 +95,7 @@
File fd;
if (zip_fd != -1) {
if (ReadMagicAndReset(zip_fd, &magic, error_msg)) {
- fd = File(zip_fd, false /* check_usage */);
+ fd = File(DupCloexec(zip_fd), false /* check_usage */);
}
} else {
fd = OpenAndReadMagic(filename, &magic, error_msg);
diff --git a/libprofile/profile/profile_compilation_info.cc b/libprofile/profile/profile_compilation_info.cc
index c765345..9b70e62 100644
--- a/libprofile/profile/profile_compilation_info.cc
+++ b/libprofile/profile/profile_compilation_info.cc
@@ -34,6 +34,7 @@
#include "base/arena_allocator.h"
#include "base/dumpable.h"
+#include "base/file_utils.h"
#include "base/logging.h" // For VLOG.
#include "base/malloc_arena_pool.h"
#include "base/os.h"
@@ -1171,7 +1172,8 @@
source->reset(ProfileSource::Create(fd));
return kProfileLoadSuccess;
} else {
- std::unique_ptr<ZipArchive> zip_archive(ZipArchive::OpenFromFd(fd, "profile", error));
+ std::unique_ptr<ZipArchive> zip_archive(
+ ZipArchive::OpenFromFd(DupCloexec(fd), "profile", error));
if (zip_archive.get() == nullptr) {
*error = "Could not open the profile zip archive";
return kProfileLoadBadData;