Skip to content

Commit e72fe16

Browse files
committed
Prevent overflow in LocationRequest.setExpireIn()
Prevent overflow in LocationRequest.setExpireIn(), for example, when we pass in Long.MAX_VALUE. Bug: 7047435 Change-Id: Ie56928a59fb387173fbd3887c0ef9aede00f8152
1 parent 57e6203 commit e72fe16

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

location/java/android/location/LocationRequest.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,15 @@ public long getFastestInterval() {
369369
* @return the same object, so that setters can be chained
370370
*/
371371
public LocationRequest setExpireIn(long millis) {
372-
mExpireAt = millis + SystemClock.elapsedRealtime();
372+
long elapsedRealtime = SystemClock.elapsedRealtime();
373+
374+
// Check for > Long.MAX_VALUE overflow (elapsedRealtime > 0):
375+
if (millis > Long.MAX_VALUE - elapsedRealtime) {
376+
mExpireAt = Long.MAX_VALUE;
377+
} else {
378+
mExpireAt = millis + elapsedRealtime;
379+
}
380+
373381
if (mExpireAt < 0) mExpireAt = 0;
374382
return this;
375383
}

0 commit comments

Comments
 (0)