cowbell / cordova-plugin-geofence

Geofencing plugin for cordova
Apache License 2.0
264 stars 318 forks source link

Add try-catch to avoid application crash for invalid geofence parameters (Android) #259

Open deton opened 6 years ago

deton commented 6 years ago

Android application crashes if invalid latitude, longitude or radius is specified from geofence plugin JavaScript API.

For example:

window.geofence.addOrUpdate({id: "test", latitude: 91, longitude: 1, radius: 100, transitionType: 3});

Sample HTML/JS to reproduce crash: https://gist.github.com/deton/d25afb2ae7ac794189c5550fc0edad45

logcat:

D/GeofencePlugin: GeofencePlugin execute action: addOrUpdate args: [{"id":"test","latitude":91,"longitude":1,"radius":100,"transitionType":3}]

                  --------- beginning of crash
E/AndroidRuntime: FATAL EXCEPTION: pool-1-thread-2
                  Process: io.github.deton.geofencetest, PID: 4338
                  java.lang.IllegalArgumentException: invalid latitude: 91.0
                      at com.google.android.gms.internal.zzcfs.<init>(Unknown Source)
                      at com.google.android.gms.location.Geofence$Builder.build(Unknown Source)
                      at com.cowbell.cordova.geofence.GeoNotification.toGeofence(GeoNotification.java:23)
                      at com.cowbell.cordova.geofence.GeoNotificationManager.addGeoNotifications(GeoNotificationManager.java:73)
                      at com.cowbell.cordova.geofence.GeofencePlugin$1.run(GeofencePlugin.java:80)
                      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
                      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
                      at java.lang.Thread.run(Thread.java:818)