From e243f77fa9dcaea116dfd010e23605b45f36c697 Mon Sep 17 00:00:00 2001 From: cyberta Date: Thu, 16 Apr 2026 01:49:47 +0200 Subject: catch possible nullpointer exceptions when accessing eipService properties. They can be null if the provider backend is misconfigured for some reason --- .../java/se/leap/bitmaskclient/eip/Gateway.java | 41 +++++++++++++++------- 1 file changed, 29 insertions(+), 12 deletions(-) (limited to 'app/src/main/java/se/leap/bitmaskclient/eip') diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java b/app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java index b207d6e8..73ba7ae1 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java @@ -30,6 +30,8 @@ import static se.leap.bitmaskclient.base.models.Constants.TIMEZONE; import static se.leap.bitmaskclient.base.models.Constants.VERSION; import static se.leap.bitmaskclient.base.models.Transport.createTransportsFrom; +import android.util.Log; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -125,7 +127,12 @@ public class Gateway { this.remoteIpAddress = modelsGateway.getIpAddr(); this.remoteIpAddressV6 = modelsGateway.getIp6Addr(); this.host = modelsGateway.getHost(); - ModelsLocation modelsLocation = eipService.getLocations().get(modelsGateway.getLocation()); + ModelsLocation modelsLocation = null; + try { + modelsLocation = eipService.getLocations().get(modelsGateway.getLocation()); + } catch (NullPointerException npe) { + Log.e(TAG, "No locations configured in service endpoint. This smells like a provider misconfiguration."); + } if (modelsLocation != null) { this.locationName = modelsLocation.getDisplayName(); this.timezone = Integer.parseInt(modelsLocation.getTimezone()); @@ -147,7 +154,12 @@ public class Gateway { this.modelsBridges.add(modelsBridge); remoteIpAddress = modelsBridge.getIpAddr(); host = modelsBridge.getHost(); - ModelsLocation modelsLocation = eipService.getLocations().get(modelsBridge.getLocation()); + ModelsLocation modelsLocation = null; + try { + modelsLocation = eipService.getLocations().get(modelsBridge.getLocation()); + } catch (NullPointerException npe) { + Log.e(TAG, "No locations configured in service endpoint. This smells like a provider misconfiguration."); + } if (modelsLocation != null) { this.locationName = modelsLocation.getDisplayName(); this.timezone = Integer.parseInt(modelsLocation.getTimezone()); @@ -179,19 +191,24 @@ public class Gateway { private JSONObject getGeneralConfiguration(ModelsEIPService eipService) { JSONObject config = new JSONObject(); - Map openvpnOptions = eipService.getOpenvpnConfiguration(); - Set keys = openvpnOptions.keySet(); - Iterator i = keys.iterator(); - while (i.hasNext()) { - try { - String key = i.next(); - Object o = openvpnOptions.get(key); - config.put(key, o); - } catch (JSONException e) { - e.printStackTrace(); + try { + Map openvpnOptions = eipService.getOpenvpnConfiguration(); + Set keys = openvpnOptions.keySet(); + Iterator i = keys.iterator(); + while (i.hasNext()) { + try { + String key = i.next(); + Object o = openvpnOptions.get(key); + config.put(key, o); + } catch (JSONException e) { + e.printStackTrace(); + } } + } catch (NullPointerException npe) { + Log.e(TAG, "Failed to get openvpn configuration. This smells like a provider misconfiguration"); } + return config; } -- cgit v1.2.3