From e6aca0e25632429f1f5c432a55b867cd9b5df22f Mon Sep 17 00:00:00 2001 From: John Turnipseed Date: Wed, 3 Nov 2021 17:39:01 -0500 Subject: [PATCH] Fixed potential heap overflow issue with 'Socket.recvData' and 'Socket.readData' --- Sources/Socket/Packet.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Socket/Packet.swift b/Sources/Socket/Packet.swift index a144b11..836e9e7 100644 --- a/Sources/Socket/Packet.swift +++ b/Sources/Socket/Packet.swift @@ -10,7 +10,7 @@ extension Socket { // Loop through all of grouped message bytes while (total < Int(length)) { - received += try recv(length: size_t(length), result: result.withUnsafeMutableBytes { $0.baseAddress! } + total, flags: flags) + received += try recv(length: size_t(length)-total, result: result.withUnsafeMutableBytes { $0.baseAddress! } + total, flags: flags) total += received // Check for recv errors @@ -30,7 +30,7 @@ extension Socket { // Loop through all of grouped message bytes while (total < Int(length)) { - read += try self.read(length: size_t(length), result: result.withUnsafeMutableBytes { $0.baseAddress! } + total) + read += try self.read(length: size_t(length)-total, result: result.withUnsafeMutableBytes { $0.baseAddress! } + total) total += read // Check for recv errors