diff options
author | 2020-01-31 13:35:12 -0800 | |
---|---|---|
committer | 2020-02-08 02:41:12 +0000 | |
commit | c9fa770b6eedcf0cfe05b2449423f5494eecfce0 (patch) | |
tree | 684657b011f8980da10cbdc89ca6288d933a2734 /runtime/class_loader_context_test.cc | |
parent | a7d98b9560166eddaeb78d0f19402ee80ec9df06 (diff) |
Introduce VMRuntime.isValidClassLoaderContext
In the PackageManager server we need to validate class loader contexts
that we receive from an untrusted process. In order to keep class loader
context parsing logic centralized within the runtime let's create an API
which returns whether or not the runtime can parse the encoded class
loader context.
Test: Build system image, open app using secondary dex
Test: atest atest com.android.server.pm.dex.DexManagerTests
Test: m test-art-host-gtest-class_loader_context_test
Change-Id: Ied676e3239f70a8ab9d066df79f377b7036b28b7
Diffstat (limited to 'runtime/class_loader_context_test.cc')
-rw-r--r-- | runtime/class_loader_context_test.cc | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/runtime/class_loader_context_test.cc b/runtime/class_loader_context_test.cc index e082c8cbcf..4d7e390b9a 100644 --- a/runtime/class_loader_context_test.cc +++ b/runtime/class_loader_context_test.cc @@ -1316,6 +1316,20 @@ TEST_F(ClassLoaderContextTest, EncodeContextsForUnsupportedChainMultiDex) { encodings.at(GetTestDexFileName("MultiDex"))); } +TEST_F(ClassLoaderContextTest, IsValidEncoding) { + ASSERT_TRUE(ClassLoaderContext::IsValidEncoding("PCL[]")); + ASSERT_TRUE(ClassLoaderContext::IsValidEncoding("PCL[foo.dex]")); + ASSERT_TRUE(ClassLoaderContext::IsValidEncoding("PCL[foo.dex];PCL[bar.dex]")); + ASSERT_TRUE(ClassLoaderContext::IsValidEncoding("DLC[];PCL[bar.dex]")); + ASSERT_TRUE( + ClassLoaderContext::IsValidEncoding( + ClassLoaderContext::kUnsupportedClassLoaderContextEncoding)); + ASSERT_FALSE(ClassLoaderContext::IsValidEncoding("not_valid")); + ASSERT_FALSE(ClassLoaderContext::IsValidEncoding("[]")); + ASSERT_FALSE(ClassLoaderContext::IsValidEncoding("FCL[]")); + ASSERT_FALSE(ClassLoaderContext::IsValidEncoding("foo.dex:bar.dex")); +} + // TODO(calin) add a test which creates the context for a class loader together with dex_elements. TEST_F(ClassLoaderContextTest, CreateContextForClassLoader) { // The chain is |