summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jeremy Meyer <jakmcbane@google.com> 2023-02-14 00:21:19 +0000
committer Jeremy Meyer <jakmcbane@google.com> 2023-02-14 22:55:00 +0000
commit12312e073546b1dab9ee80c7ab28a4c55c3102a8 (patch)
treec3e2786dccbbf33c684cb1326b20b9e5a0ecd9c7
parent1a936d17c05c185dfa5794508564aa01514a08d9 (diff)
Fix checking for subdirs when parsing apks
This fixes the check for subdirectories in lib paths. The old check caused a crash. Test: Automated Fixes: 268582810 Change-Id: I520f1fd6772b11821e7c5c97bd51b45b603f5a7b
-rw-r--r--libs/androidfw/ApkParsing.cpp6
-rw-r--r--libs/androidfw/tests/ApkParsing_test.cpp6
2 files changed, 8 insertions, 4 deletions
diff --git a/libs/androidfw/ApkParsing.cpp b/libs/androidfw/ApkParsing.cpp
index cf4fbb9b8462..32d2c5b05acb 100644
--- a/libs/androidfw/ApkParsing.cpp
+++ b/libs/androidfw/ApkParsing.cpp
@@ -56,10 +56,8 @@ const char* ValidLibraryPathLastSlash(const char* fileName, bool suppress64Bit,
return nullptr;
}
- // Make sure there aren't subdirectories
- const char* abiOffset = fileName + APK_LIB_LEN;
- const size_t abiSize = lastSlash - abiOffset;
- if (memchr(abiOffset, '/', abiSize)) {
+ // 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 4aab0a146ecf..62e88c619e5c 100644
--- a/libs/androidfw/tests/ApkParsing_test.cpp
+++ b/libs/androidfw/tests/ApkParsing_test.cpp
@@ -68,4 +68,10 @@ TEST(ApkParsingTest, InvalidSubdirectories) {
auto lastSlash = util::ValidLibraryPathLastSlash(path, false, false);
ASSERT_THAT(lastSlash, IsNull());
}
+
+TEST(ApkParsingTest, InvalidFileAtRoot) {
+ const char* path = "lib/library.so";
+ auto lastSlash = util::ValidLibraryPathLastSlash(path, false, false);
+ ASSERT_THAT(lastSlash, IsNull());
+}
} \ No newline at end of file