From 1a24e4231b1edd5e6dc1779d6377533859b61976 Mon Sep 17 00:00:00 2001 From: H William Welliver <william@welliver.org> Date: Fri, 4 Dec 2020 18:03:39 -0500 Subject: [PATCH] SSL.File: if there's received data yet to be read, allow it to be returned, regardless of whether the connection is open. --- lib/modules/SSL.pmod/File.pike | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/modules/SSL.pmod/File.pike b/lib/modules/SSL.pmod/File.pike index 45d78f8f4e..3360ee4ef9 100644 --- a/lib/modules/SSL.pmod/File.pike +++ b/lib/modules/SSL.pmod/File.pike @@ -889,8 +889,6 @@ string read (void|int length, void|int(0..1) not_all) SSL3_DEBUG_MSG ("SSL.File->read (%d, %d)\n", length, not_all); ENTER (0) { - if (close_state > STREAM_OPEN) error ("Not open.\n"); - if (read_errno && !sizeof(user_read_buffer)) { local_errno = read_errno; SSL3_DEBUG_MSG ("SSL.File->read: Propagating old callback error: %s\n", @@ -924,6 +922,12 @@ string read (void|int length, void|int(0..1) not_all) } } + // if the stream is closed and the buffer contains no unread data, + // throw an exception. this allows data receieved to be retrieved + // even if the read happens after the stream is closed. + if (close_state > STREAM_OPEN && !sizeof(user_read_buffer)) + error ("Not open.\n"); + string res = user_read_buffer->try_read(length); read_buffer_threshold = Stdio.DATA_CHUNK_SIZE; -- GitLab