summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreehugger Robot <treehugger-gerrit@google.com>2022-08-15 15:29:19 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2022-08-15 15:29:19 +0000
commita7459772bbc558b8b13df09de8b0cea156d81870 (patch)
treebaa41de5d29e6616c4276055cc04e497a01dd505
parentfc3c2a1384ded74a621b38d8d009aa37c067222b (diff)
parent372c4810c7392aa40cd230910d83cf638dbb368b (diff)
downloadnative-temp_sam_242648940.tar.gz
Merge changes Ia3eae81c,Iff44fb23 am: 372c4810c7temp_sam_242648940
Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/2184409 Change-Id: I3b19cc0de68c97cbea32b688d73c16a6ef2f069c Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--cmds/installd/InstalldNativeService.cpp39
-rw-r--r--cmds/installd/tests/installd_dexopt_test.cpp52
2 files changed, 91 insertions, 0 deletions
diff --git a/cmds/installd/InstalldNativeService.cpp b/cmds/installd/InstalldNativeService.cpp
index 1d7dd5f51e..6ee3070306 100644
--- a/cmds/installd/InstalldNativeService.cpp
+++ b/cmds/installd/InstalldNativeService.cpp
@@ -230,6 +230,19 @@ binder::Status checkArgumentPath(const std::optional<std::string>& path) {
}
}
+binder::Status checkArgumentFileName(const std::string& path) {
+ if (path.empty()) {
+ return exception(binder::Status::EX_ILLEGAL_ARGUMENT, "Missing name");
+ }
+ for (const char& c : path) {
+ if (c == '\0' || c == '\n' || c == '/') {
+ return exception(binder::Status::EX_ILLEGAL_ARGUMENT,
+ StringPrintf("Name %s is malformed", path.c_str()));
+ }
+ }
+ return ok();
+}
+
#define ENFORCE_UID(uid) { \
binder::Status status = checkUid((uid)); \
if (!status.isOk()) { \
@@ -266,6 +279,14 @@ binder::Status checkArgumentPath(const std::optional<std::string>& path) {
} \
}
+#define CHECK_ARGUMENT_FILE_NAME(path) \
+ { \
+ binder::Status status = checkArgumentFileName((path)); \
+ if (!status.isOk()) { \
+ return status; \
+ } \
+ }
+
#ifdef GRANULAR_LOCKS
/**
@@ -1006,6 +1027,12 @@ binder::Status InstalldNativeService::clearAppProfiles(const std::string& packag
const std::string& profileName) {
ENFORCE_UID(AID_SYSTEM);
CHECK_ARGUMENT_PACKAGE_NAME(packageName);
+ CHECK_ARGUMENT_FILE_NAME(profileName);
+ if (!base::EndsWith(profileName, ".prof")) {
+ return exception(binder::Status::EX_ILLEGAL_ARGUMENT,
+ StringPrintf("Profile name %s does not end with .prof",
+ profileName.c_str()));
+ }
LOCK_PACKAGE();
binder::Status res = ok();
@@ -3025,7 +3052,19 @@ binder::Status InstalldNativeService::copySystemProfile(const std::string& syste
int32_t packageUid, const std::string& packageName, const std::string& profileName,
bool* _aidl_return) {
ENFORCE_UID(AID_SYSTEM);
+ CHECK_ARGUMENT_PATH(systemProfile);
+ if (!base::EndsWith(systemProfile, ".prof")) {
+ return exception(binder::Status::EX_ILLEGAL_ARGUMENT,
+ StringPrintf("System profile path %s does not end with .prof",
+ systemProfile.c_str()));
+ }
CHECK_ARGUMENT_PACKAGE_NAME(packageName);
+ CHECK_ARGUMENT_FILE_NAME(profileName);
+ if (!base::EndsWith(profileName, ".prof")) {
+ return exception(binder::Status::EX_ILLEGAL_ARGUMENT,
+ StringPrintf("Profile name %s does not end with .prof",
+ profileName.c_str()));
+ }
LOCK_PACKAGE();
*_aidl_return = copy_system_profile(systemProfile, packageUid, packageName, profileName);
return ok();
diff --git a/cmds/installd/tests/installd_dexopt_test.cpp b/cmds/installd/tests/installd_dexopt_test.cpp
index 3849c40ac2..6ef41e3258 100644
--- a/cmds/installd/tests/installd_dexopt_test.cpp
+++ b/cmds/installd/tests/installd_dexopt_test.cpp
@@ -1371,6 +1371,58 @@ TEST_F(ProfileTest, ProfilePrepareFailProfileChangedUid) {
/*has_user_id*/ true, /*expected_result*/ false);
}
+TEST_F(ProfileTest, ClearAppProfilesOk) {
+ LOG(INFO) << "ClearAppProfilesOk";
+
+ ASSERT_BINDER_SUCCESS(service_->clearAppProfiles(package_name_, "primary.prof"));
+ ASSERT_BINDER_SUCCESS(service_->clearAppProfiles(package_name_, "image_editor.split.prof"));
+}
+
+TEST_F(ProfileTest, ClearAppProfilesFailWrongProfileName) {
+ LOG(INFO) << "ClearAppProfilesFailWrongProfileName";
+
+ ASSERT_BINDER_FAIL(
+ service_->clearAppProfiles(package_name_,
+ "../../../../dalvik-cache/arm64/"
+ "system@app@SecureElement@SecureElement.apk@classes.vdex"));
+ ASSERT_BINDER_FAIL(service_->clearAppProfiles(package_name_, "image_editor.split.apk"));
+}
+
+TEST_F(ProfileTest, CopySystemProfileOk) {
+ LOG(INFO) << "CopySystemProfileOk";
+
+ bool result;
+ ASSERT_BINDER_SUCCESS(
+ service_->copySystemProfile("/data/app/random.string/package.name.random/base.apk.prof",
+ kTestAppUid, package_name_, "primary.prof", &result));
+}
+
+TEST_F(ProfileTest, CopySystemProfileFailWrongSystemProfilePath) {
+ LOG(INFO) << "CopySystemProfileFailWrongSystemProfilePath";
+
+ bool result;
+ ASSERT_BINDER_FAIL(service_->copySystemProfile("../../secret.dat", kTestAppUid, package_name_,
+ "primary.prof", &result));
+ ASSERT_BINDER_FAIL(service_->copySystemProfile("/data/user/package.name/secret.data",
+ kTestAppUid, package_name_, "primary.prof",
+ &result));
+}
+
+TEST_F(ProfileTest, CopySystemProfileFailWrongProfileName) {
+ LOG(INFO) << "CopySystemProfileFailWrongProfileName";
+
+ bool result;
+ ASSERT_BINDER_FAIL(
+ service_->copySystemProfile("/data/app/random.string/package.name.random/base.apk.prof",
+ kTestAppUid, package_name_,
+ "../../../../dalvik-cache/arm64/test.vdex", &result));
+ ASSERT_BINDER_FAIL(
+ service_->copySystemProfile("/data/app/random.string/package.name.random/base.apk.prof",
+ kTestAppUid, package_name_, "/test.prof", &result));
+ ASSERT_BINDER_FAIL(
+ service_->copySystemProfile("/data/app/random.string/package.name.random/base.apk.prof",
+ kTestAppUid, package_name_, "base.apk", &result));
+}
class BootProfileTest : public ProfileTest {
public: