Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5575ddfc authored by David Christie's avatar David Christie
Browse files

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
parent 78031818
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -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);
            }