NetworkExtension: check isTunnelClosed before packet existence

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jason A. Donenfeld 2018-11-01 22:01:52 +01:00
parent cf569fd0d2
commit b21de2e398
1 changed files with 2 additions and 2 deletions

View File

@ -163,9 +163,9 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
guard let buf = buf else { return 0 }
let wgContext = wgCtxPtr.bindMemory(to: WireGuardContext.self, capacity: 1).pointee
var isTunnelClosed = false
guard let packet = wgContext.readPacket(isTunnelClosed: &isTunnelClosed) else { return 0 }
let packet = wgContext.readPacket(isTunnelClosed: &isTunnelClosed)
if isTunnelClosed { return -1 }
let packetData = packet.data
guard let packetData = packet?.data else { return 0 }
if packetData.count <= len {
packetData.copyBytes(to: buf, count: packetData.count)
return packetData.count