WireGuardKit: Only assign self.settingsGenerator upon success to set tunnel network settings to avoid inconsistent state
Signed-off-by: Andrej Mihajlov <and@mullvad.net>
This commit is contained in:
parent
2e356d3d8f
commit
b34625f511
|
@ -263,7 +263,6 @@ public class WireGuardAdapter {
|
||||||
|
|
||||||
let settingsGenerator = PacketTunnelSettingsGenerator(tunnelConfiguration: tunnelConfiguration, resolvedEndpoints: resolvedEndpoints)
|
let settingsGenerator = PacketTunnelSettingsGenerator(tunnelConfiguration: tunnelConfiguration, resolvedEndpoints: resolvedEndpoints)
|
||||||
let networkSettings = settingsGenerator.generateNetworkSettings()
|
let networkSettings = settingsGenerator.generateNetworkSettings()
|
||||||
self.settingsGenerator = settingsGenerator
|
|
||||||
|
|
||||||
var systemError: Error?
|
var systemError: Error?
|
||||||
let condition = NSCondition()
|
let condition = NSCondition()
|
||||||
|
@ -284,6 +283,11 @@ public class WireGuardAdapter {
|
||||||
if condition.wait(until: Date().addingTimeInterval(setTunnelNetworkSettingsTimeout)) {
|
if condition.wait(until: Date().addingTimeInterval(setTunnelNetworkSettingsTimeout)) {
|
||||||
let returnError = systemError.map { WireGuardAdapterError.setNetworkSettings($0) }
|
let returnError = systemError.map { WireGuardAdapterError.setNetworkSettings($0) }
|
||||||
|
|
||||||
|
// Only assign `settingsGenerator` when `setTunnelNetworkSettings` succeeded.
|
||||||
|
if returnError == nil {
|
||||||
|
self.settingsGenerator = settingsGenerator
|
||||||
|
}
|
||||||
|
|
||||||
completionHandler(settingsGenerator, returnError)
|
completionHandler(settingsGenerator, returnError)
|
||||||
} else {
|
} else {
|
||||||
completionHandler(nil, .setNetworkSettingsTimeout)
|
completionHandler(nil, .setNetworkSettingsTimeout)
|
||||||
|
|
Loading…
Reference in New Issue