From 8e3f12f30546380c6fe7564adc5344c7e4b4380e Mon Sep 17 00:00:00 2001 From: Haoran Zhang Date: Sat, 18 Feb 2023 00:05:49 +0000 Subject: [PATCH] Since we are using string.subString(startIndex, endIndex) when parsing denylist, we should make sure startIndex <= endIndex before calling string.substring(). Otherwise, an index out of bound excpetion would throw and make the app terminate. This could happen if we are not careful with the denylist and make the denylist wrong formatted. For example, a ";" is left out in the end, and startIndex in this case would become -1. When we find the denylist is not properly formatted on framework, we could print an error in log stating the denylist is wrongly formatted and go ahead treating this app as not denied. Test: atest cts/tests/autofillservice/src/android/autofillservice/cts/servicebehavior/AutofillForAllAppsTest.java Bug:269775456 Change-Id: I7fb87ec18880550a07533d6be079991268120041 --- core/java/android/view/autofill/AutofillManager.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/java/android/view/autofill/AutofillManager.java b/core/java/android/view/autofill/AutofillManager.java index bdc7333f27510..aef0e651ff8dd 100644 --- a/core/java/android/view/autofill/AutofillManager.java +++ b/core/java/android/view/autofill/AutofillManager.java @@ -899,9 +899,10 @@ public final class AutofillManager { // 3. Get the activity names substring between the indexes final int activityStringStartIndex = packageInStringIndex + packageName.length() + 1; - if (activityStringStartIndex < firstNextSemicolonIndex) { + if (activityStringStartIndex >= firstNextSemicolonIndex) { Log.e(TAG, "Failed to get denied activity names from denylist because it's wrongly " + "formatted"); + return; } final String activitySubstring = denyListString.substring(activityStringStartIndex, firstNextSemicolonIndex);