From 5575ddfcc1a1a7873d493ad6bbc522a9652d4ffc Mon Sep 17 00:00:00 2001 From: David Christie Date: Tue, 27 Oct 2015 13:29:14 -0700 Subject: [PATCH] Correct range checking for location strings during conversion Minute values in the range [0, 59] are valid if seconds are present. If seconds are not present then minute values are valid in the range [0, <60] Second values are valid in the range [0, <60] Examples: 50:59:59.99999 is valid 50:59.99999 is valid 50:59.1:1 is not valid Patch taken from Motorola: partner gerrit 137210 Bug: 17958582 Change-Id: I0d1265534092157883af564119f723984362d436 Issues: 2667 and 2668 --- location/java/android/location/Location.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/location/java/android/location/Location.java b/location/java/android/location/Location.java index bf3387bb8059..bca9be673f5d 100644 --- a/location/java/android/location/Location.java +++ b/location/java/android/location/Location.java @@ -257,11 +257,13 @@ public class Location implements Parcelable { int deg = Integer.parseInt(degrees); double min; double sec = 0.0; + boolean secPresent = false; if (st.hasMoreTokens()) { min = Integer.parseInt(minutes); String seconds = st.nextToken(); sec = Double.parseDouble(seconds); + secPresent = true; } else { min = Double.parseDouble(minutes); } @@ -273,11 +275,15 @@ public class Location implements Parcelable { if ((deg < 0.0) || (deg > 179 && !isNegative180)) { throw new IllegalArgumentException("coordinate=" + coordinate); } - if (min < 0 || min > 59) { + + // min must be in [0, 59] if seconds are present, otherwise [0.0, 60.0) + if (min < 0 || min >= 60 || (secPresent && (min > 59))) { throw new IllegalArgumentException("coordinate=" + coordinate); } - if (sec < 0 || sec > 59) { + + // sec must be in [0.0, 60.0) + if (sec < 0 || sec >= 60) { throw new IllegalArgumentException("coordinate=" + coordinate); } -- 2.11.0