From ea50f804a46c310abdd95b5e8a75386c78581898 Mon Sep 17 00:00:00 2001 From: Kouji Shiotani Date: Thu, 16 Mar 2017 15:20:49 +0900 Subject: [PATCH] Fix wrong array index bound in NotificationUsageStats Symptom: It's possible to cause ArrayIndexOutOfBoundsException. Root cause: There is an error in the argument check, there is a possibility of accessing an incorrect Index Solution: Fix the argument check correctly Bug: 36542230 Change-Id: I3dea387c4a2bbddcc68db06812b57fd9d300f778 --- .../android/server/notification/NotificationUsageStats.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/notification/NotificationUsageStats.java b/services/core/java/com/android/server/notification/NotificationUsageStats.java index 34c52833fbfde..4265741481817 100644 --- a/services/core/java/com/android/server/notification/NotificationUsageStats.java +++ b/services/core/java/com/android/server/notification/NotificationUsageStats.java @@ -40,6 +40,7 @@ import org.json.JSONException; import org.json.JSONObject; import java.io.PrintWriter; +import java.lang.Math; import java.util.ArrayDeque; import java.util.Calendar; import java.util.GregorianCalendar; @@ -718,8 +719,8 @@ public class NotificationUsageStats { } void increment(int imp) { - imp = imp < 0 ? 0 : imp > NUM_IMPORTANCES ? NUM_IMPORTANCES : imp; - mCount[imp] ++; + imp = Math.max(0, Math.min(imp, mCount.length - 1)); + mCount[imp]++; } void maybeCount(ImportanceHistogram prev) {