File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed
Sources/PostgresClientKit Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -136,6 +136,11 @@ public class Connection: CustomStringConvertible {
136136 throw PostgresError . sslNotSupported
137137 }
138138
139+ // The read buffer should be fully consumed at this point, so that the next byte read
140+ // will have passed through SSL/TLS decryption. If this is not the case, there must
141+ // either be a server protocol error or a man-in-the-middle attack.
142+ try verifyReadBufferFullyConsumed ( )
143+
139144 do {
140145 let sslConfig = configuration. sslServiceConfiguration
141146 let sslService = try SSLService ( usingConfiguration: sslConfig) !
@@ -1212,6 +1217,12 @@ public class Connection: CustomStringConvertible {
12121217 return c
12131218 }
12141219
1220+ private func verifyReadBufferFullyConsumed( ) throws {
1221+ guard readBufferPosition == readBuffer. count else {
1222+ throw PostgresError . serverError ( description: " response too long " )
1223+ }
1224+ }
1225+
12151226 private func refillReadBuffer( ) throws {
12161227
12171228 assert ( readBufferPosition == readBuffer. count)
You can’t perform that action at this time.
0 commit comments