Skip to content

Commit f387ff0

Browse files
samantharitterkevinAlbs
authored andcommitted
CDRIVER-3318 pass correct message length to SSLRead
1 parent 2493b96 commit f387ff0

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/libmongoc/src/mongoc/mongoc-stream-tls-secure-transport.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,9 @@ _mongoc_stream_tls_secure_transport_readv (mongoc_stream_t *stream,
298298
size_t iov_pos = 0;
299299
int64_t now;
300300
int64_t expire = 0;
301+
size_t to_read;
302+
size_t remaining_buf_size;
303+
size_t remaining_to_read;
301304

302305
BSON_ASSERT (iov);
303306
BSON_ASSERT (iovcnt);
@@ -314,9 +317,23 @@ _mongoc_stream_tls_secure_transport_readv (mongoc_stream_t *stream,
314317
iov_pos = 0;
315318

316319
while (iov_pos < iov[i].iov_len) {
320+
321+
remaining_buf_size = iov[i].iov_len - iov_pos;
322+
remaining_to_read = min_bytes - ret;
323+
324+
/* The third argument passed to SSLRead is an all-or-nothing
325+
dataLength, which it will attempt to read until it succeeds or
326+
times out. If our buffer is larger than the message we expect
327+
to read, choose the smaller number of the two. */
328+
if (remaining_to_read > 0 && remaining_to_read < remaining_buf_size) {
329+
to_read = remaining_to_read;
330+
} else {
331+
to_read = remaining_buf_size;
332+
}
333+
317334
OSStatus status = SSLRead (secure_transport->ssl_ctx_ref,
318335
(char *) iov[i].iov_base + iov_pos,
319-
(int) (iov[i].iov_len - iov_pos),
336+
to_read,
320337
&read_ret);
321338

322339
if (status != noErr) {

0 commit comments

Comments
 (0)