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
This commit is contained in:
Kouji Shiotani
2017-03-16 15:20:49 +09:00
committed by Shunta Sato
parent 4a8953094f
commit ea50f804a4

View File

@@ -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) {