summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2022-07-12 10:22:32 +0200
committerAndrej Mihajlov <and@mullvad.net>2022-07-12 14:27:57 +0200
commit2aeb6c152ee080a23a66e35a8933f6d8fb4768bc (patch)
tree0de4abed14ce543e669d05976d989e0d834a1d55
parenta127de75e33af3bfc42e9e8bf049cb4447430223 (diff)
downloadmullvadvpn-2aeb6c152ee080a23a66e35a8933f6d8fb4768bc.tar.xz
mullvadvpn-2aeb6c152ee080a23a66e35a8933f6d8fb4768bc.zip
Make geojson loader safer
-rw-r--r--ios/MullvadVPN/ConnectViewController.swift21
1 files changed, 17 insertions, 4 deletions
diff --git a/ios/MullvadVPN/ConnectViewController.swift b/ios/MullvadVPN/ConnectViewController.swift
index 8673f8a23b..44475e603b 100644
--- a/ios/MullvadVPN/ConnectViewController.swift
+++ b/ios/MullvadVPN/ConnectViewController.swift
@@ -24,6 +24,8 @@ protocol ConnectViewControllerDelegate: AnyObject {
class ConnectViewController: UIViewController, MKMapViewDelegate, RootContainment, TunnelObserver {
+ private static let geoJSONSourceFileName = "countries.geo.json"
+
weak var delegate: ConnectViewControllerDelegate?
let notificationController = NotificationController()
@@ -438,11 +440,22 @@ class ConnectViewController: UIViewController, MKMapViewDelegate, RootContainmen
}
private func loadGeoJSONData() {
- let fileURL = Bundle.main.url(forResource: "countries.geo", withExtension: "json")!
- let data = try! Data(contentsOf: fileURL)
+ guard let fileURL = Bundle.main.url(
+ forResource: Self.geoJSONSourceFileName,
+ withExtension: nil
+ ) else {
+ logger.debug("Failed to locate \(Self.geoJSONSourceFileName) in main bundle.")
+ return
+ }
- let overlays = try! GeoJSON.decodeGeoJSON(data)
- mainContentView.mapView.addOverlays(overlays, level: .aboveLabels)
+ do {
+ let data = try Data(contentsOf: fileURL)
+ let overlays = try GeoJSON.decodeGeoJSON(data)
+
+ mainContentView.mapView.addOverlays(overlays)
+ } catch {
+ logger.error(chainedError: AnyChainedError(error), message: "Failed to load geojson.")
+ }
}
}