Skip to content

Commit 6d9e59d

Browse files
chaenweb-flow
authored andcommitted
sweep: #8028 fix (Core): limit read to TLS payload size
1 parent 970b50f commit 6d9e59d

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/DIRAC/Core/DISET/private/Transports/BaseTransport.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
1818
Client <- Service : Close
1919
"""
20+
2021
import time
2122
from io import BytesIO
2223
from hashlib import md5
@@ -27,6 +28,9 @@
2728
from DIRAC.FrameworkSystem.Client.Logger import gLogger
2829
from DIRAC.Core.Utilities import MixedEncode
2930

31+
# https://datatracker.ietf.org/doc/html/rfc8446#section-5.1
32+
TLS_PAYLOAD_SIZE = 16384
33+
3034

3135
class BaseTransport:
3236
"""Invokes MixedEncode for marshaling/unmarshaling of data calls in transit"""
@@ -198,7 +202,7 @@ def receiveData(self, maxBufferSize=0, blockAfterKeepAlive=True, idleReceive=Fal
198202
isKeepAlive = self.byteStream.find(BaseTransport.keepAliveMagic, 0, keepAliveMagicLen) == 0
199203
# While not found the message length or the ka, keep receiving
200204
while iSeparatorPosition == -1 and not isKeepAlive:
201-
retVal = self._read(16384)
205+
retVal = self._read(TLS_PAYLOAD_SIZE)
202206
# If error return
203207
if not retVal["OK"]:
204208
return retVal
@@ -225,6 +229,7 @@ def receiveData(self, maxBufferSize=0, blockAfterKeepAlive=True, idleReceive=Fal
225229
pkgSize = int(self.byteStream[:iSeparatorPosition])
226230
pkgData = self.byteStream[iSeparatorPosition + 1 :]
227231
readSize = len(pkgData)
232+
228233
if readSize >= pkgSize:
229234
# If we already have all the data we need
230235
data = pkgData[:pkgSize]
@@ -235,7 +240,7 @@ def receiveData(self, maxBufferSize=0, blockAfterKeepAlive=True, idleReceive=Fal
235240
pkgMem.write(pkgData)
236241
# Receive while there's still data to be received
237242
while readSize < pkgSize:
238-
retVal = self._read(pkgSize - readSize, skipReadyCheck=True)
243+
retVal = self._read(min(TLS_PAYLOAD_SIZE, pkgSize - readSize), skipReadyCheck=True)
239244
if not retVal["OK"]:
240245
return retVal
241246
if not retVal["Value"]:

src/DIRAC/Core/DISET/private/Transports/M2SSLTransport.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,8 @@ def _write(self, buf):
493493
# And writting on a socket that received an RST packet
494494
# triggers a SIGPIPE.
495495
# In practice, this means that if the server replies to a
496-
# dead client with less that 16384 bytes (see),
496+
# dead client with less that 16384 bytes
497+
# (see https://datatracker.ietf.org/doc/html/rfc8446#section-5.1),
497498
# we will never notice that we sent the answer to the vacuum.
498499
# And don't look for a fix, there just isn't.
499500
wrote = self.oSocket.write(buf)

0 commit comments

Comments
 (0)