summaryrefslogtreecommitdiff
path: root/libs/androidfw
diff options
context:
space:
mode:
author Iurii Makhno <iuriimak@google.com> 2023-02-27 16:27:26 +0000
committer Iurii Makhno <iuriimak@google.com> 2023-02-28 17:59:16 +0000
commita30d8baff4857ff8daa4da6925e4e7f12a90f41d (patch)
tree44a85dfff91e1b8979a35ea920ab72cb37659b56 /libs/androidfw
parentca75b3cdb7964d45a9e4970e11998b99e7f34ca6 (diff)
Ensure library file starts with 'lib/' prefix.
Test: ApkParsing_test.cpp Change-Id: I3a1ac8c10b315e49ec668ff357aafe861cd2d0fe
Diffstat (limited to 'libs/androidfw')
-rw-r--r--libs/androidfw/ApkParsing.cpp5
-rw-r--r--libs/androidfw/tests/ApkParsing_test.cpp6
2 files changed, 11 insertions, 0 deletions
diff --git a/libs/androidfw/ApkParsing.cpp b/libs/androidfw/ApkParsing.cpp
index 32d2c5b05acb..7eedfdb5c921 100644
--- a/libs/androidfw/ApkParsing.cpp
+++ b/libs/androidfw/ApkParsing.cpp
@@ -56,6 +56,11 @@ const char* ValidLibraryPathLastSlash(const char* fileName, bool suppress64Bit,
return nullptr;
}
+ // Make sure file starts with 'lib/' prefix.
+ if (strncmp(fileName, APK_LIB.data(), APK_LIB_LEN) != 0) {
+ return nullptr;
+ }
+
// Make sure there aren't subdirectories by checking if the next / after lib/ is the last slash
if (memchr(fileName + APK_LIB_LEN, '/', fileNameLen - APK_LIB_LEN) != lastSlash) {
return nullptr;
diff --git a/libs/androidfw/tests/ApkParsing_test.cpp b/libs/androidfw/tests/ApkParsing_test.cpp
index 62e88c619e5c..ac1dc9b88463 100644
--- a/libs/androidfw/tests/ApkParsing_test.cpp
+++ b/libs/androidfw/tests/ApkParsing_test.cpp
@@ -74,4 +74,10 @@ TEST(ApkParsingTest, InvalidFileAtRoot) {
auto lastSlash = util::ValidLibraryPathLastSlash(path, false, false);
ASSERT_THAT(lastSlash, IsNull());
}
+
+TEST(ApkParsingTest, InvalidPrefix) {
+ const char* path = "assets/libhello.so";
+ auto lastSlash = util::ValidLibraryPathLastSlash(path, false, false);
+ ASSERT_THAT(lastSlash, IsNull());
+}
} \ No newline at end of file