From 4e0bd1e973f52248a3a393dea60ee5855484e878 Mon Sep 17 00:00:00 2001 From: Winson Chiu Date: Thu, 12 May 2022 19:27:54 +0000 Subject: [PATCH] Generalize canPackageQuery error message This ensures no data leaks from reading the exception message. Bug: 230868108 Test: manual, PoC from bug Change-Id: I11963a0a9e429674732c51bd83898d0a8502ec04 --- .../com/android/server/pm/ComputerEngine.java | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/services/core/java/com/android/server/pm/ComputerEngine.java b/services/core/java/com/android/server/pm/ComputerEngine.java index bf9f4fa8a2114..168c3d8b3339a 100644 --- a/services/core/java/com/android/server/pm/ComputerEngine.java +++ b/services/core/java/com/android/server/pm/ComputerEngine.java @@ -5434,22 +5434,18 @@ public class ComputerEngine implements Computer { false /*checkShell*/, "may package query"); final PackageStateInternal sourceSetting = getPackageStateInternal(sourcePackageName); final PackageStateInternal targetSetting = getPackageStateInternal(targetPackageName); - if (sourceSetting == null || targetSetting == null) { - throw new ParcelableException(new PackageManager.NameNotFoundException("Package(s) " - + (sourceSetting == null ? sourcePackageName + " " : "") - + (targetSetting == null ? targetPackageName + " " : "") - + "not found.")); + boolean throwException = sourceSetting == null || targetSetting == null; + if (!throwException) { + final boolean filterSource = + shouldFilterApplication(sourceSetting, callingUid, userId); + final boolean filterTarget = + shouldFilterApplication(targetSetting, callingUid, userId); + // The caller must have visibility of the both packages + throwException = filterSource || filterTarget; } - final boolean filterSource = - shouldFilterApplication(sourceSetting, callingUid, userId); - final boolean filterTarget = - shouldFilterApplication(targetSetting, callingUid, userId); - // The caller must have visibility of the both packages - if (filterSource || filterTarget) { + if (throwException) { throw new ParcelableException(new PackageManager.NameNotFoundException("Package(s) " - + (filterSource ? sourcePackageName + " " : "") - + (filterTarget ? targetPackageName + " " : "") - + "not found.")); + + sourcePackageName + " and/or " + targetPackageName + " not found.")); } final int sourcePackageUid = UserHandle.getUid(userId, sourceSetting.getAppId()); return !shouldFilterApplication(targetSetting, sourcePackageUid, userId);