diff options
author | Calin Juravle <calin@google.com> | 2014-07-15 23:56:47 +0100 |
---|---|---|
committer | Calin Juravle <calin@google.com> | 2014-08-04 17:52:05 +0100 |
commit | 4e1d579d6401fef2dd57b16f8d406e33221a69d9 (patch) | |
tree | 2abc27cbd45cc8a4775df928280c63c1606cff75 /runtime/dex_file.cc | |
parent | 89c210bf418a152ccabfbbf853ddcce33aea450d (diff) | |
download | android_art-4e1d579d6401fef2dd57b16f8d406e33221a69d9.tar.gz android_art-4e1d579d6401fef2dd57b16f8d406e33221a69d9.tar.bz2 android_art-4e1d579d6401fef2dd57b16f8d406e33221a69d9.zip |
Use canonical paths when searching for dex files
Apps which use the DexPathClassLoader directly may
pass symlinks when trying to load dex files. This
will not work as we use string comparision to find
the dex in an oat file. The CL fixes this issue by
using using dex conical paths for comparisons.
Bug: 15313272
Change-Id: Ic314374b17612c3afbcadec93a88b2515a0aca5e
Diffstat (limited to 'runtime/dex_file.cc')
-rw-r--r-- | runtime/dex_file.cc | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/runtime/dex_file.cc b/runtime/dex_file.cc index e5bc7c8c86..e1a77714b9 100644 --- a/runtime/dex_file.cc +++ b/runtime/dex_file.cc @@ -951,6 +951,38 @@ std::pair<const char*, const char*> DexFile::SplitMultiDexLocation( return std::make_pair(tmp, colon_ptr + 1); } +std::string DexFile::GetMultiDexClassesDexName(size_t number, const char* dex_location) { + if (number == 0) { + return dex_location; + } else { + return StringPrintf("%s" kMultiDexSeparatorString "classes%zu.dex", dex_location, number + 1); + } +} + +std::string DexFile::GetDexCanonicalLocation(const char* dex_location) { + CHECK_NE(dex_location, static_cast<const char*>(nullptr)); + char* path = nullptr; + if (!IsMultiDexLocation(dex_location)) { + path = realpath(dex_location, nullptr); + } else { + std::pair<const char*, const char*> pair = DexFile::SplitMultiDexLocation(dex_location); + const char* dex_real_location(realpath(pair.first, nullptr)); + delete pair.first; + if (dex_real_location != nullptr) { + int length = strlen(dex_real_location) + strlen(pair.second) + strlen(kMultiDexSeparatorString) + 1; + char* multidex_canonical_location = reinterpret_cast<char*>(malloc(sizeof(char) * length)); + snprintf(multidex_canonical_location, length, "%s" kMultiDexSeparatorString "%s", dex_real_location, pair.second); + free(const_cast<char*>(dex_real_location)); + path = multidex_canonical_location; + } + } + + // If realpath fails then we just copy the argument. + std::string result(path == nullptr ? dex_location : path); + free(path); + return result; +} + std::ostream& operator<<(std::ostream& os, const DexFile& dex_file) { os << StringPrintf("[DexFile: %s dex-checksum=%08x location-checksum=%08x %p-%p]", dex_file.GetLocation().c_str(), @@ -958,6 +990,7 @@ std::ostream& operator<<(std::ostream& os, const DexFile& dex_file) { dex_file.Begin(), dex_file.Begin() + dex_file.Size()); return os; } + std::string Signature::ToString() const { if (dex_file_ == nullptr) { CHECK(proto_id_ == nullptr); |