Ensure library file starts with 'lib/' prefix.

Test: ApkParsing_test.cpp
Change-Id: I3a1ac8c10b315e49ec668ff357aafe861cd2d0fe
This commit is contained in:
Iurii Makhno
2023-02-27 16:27:26 +00:00
parent ca75b3cdb7
commit a30d8baff4
2 changed files with 11 additions and 0 deletions

View File

@@ -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;

View File

@@ -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());
}
}