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

Commit e72fe161 authored by Laurent Tu's avatar Laurent Tu
Browse files

Prevent overflow in LocationRequest.setExpireIn()

Prevent overflow in LocationRequest.setExpireIn(), for example,
when we pass in Long.MAX_VALUE.

Bug: 7047435
Change-Id: Ie56928a59fb387173fbd3887c0ef9aede00f8152
parent 57e62034
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -369,7 +369,15 @@ public final class LocationRequest implements Parcelable {
     * @return the same object, so that setters can be chained
     */
    public LocationRequest setExpireIn(long millis) {
        mExpireAt = millis + SystemClock.elapsedRealtime();
        long elapsedRealtime = SystemClock.elapsedRealtime();

        // Check for > Long.MAX_VALUE overflow (elapsedRealtime > 0):
        if (millis > Long.MAX_VALUE - elapsedRealtime) {
          mExpireAt = Long.MAX_VALUE;
        } else {
          mExpireAt = millis + elapsedRealtime;
        }

        if (mExpireAt < 0) mExpireAt = 0;
        return this;
    }