From 8239d3b358878ec4c0662a0dc2ccdc42c0e313c1 Mon Sep 17 00:00:00 2001 From: Jacob Young Date: Mon, 26 Jun 2023 21:03:40 -0400 Subject: [PATCH] crypto: recoup storage in `tls.Client.partially_read_buffer` --- lib/std/crypto/tls/Client.zig | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/std/crypto/tls/Client.zig b/lib/std/crypto/tls/Client.zig index d0b4b275a8..74dff13c70 100644 --- a/lib/std/crypto/tls/Client.zig +++ b/lib/std/crypto/tls/Client.zig @@ -958,6 +958,13 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec) // The amount of the user's buffer that will be used to give cleartext. The // beginning of the buffer will be used for such purposes. const cleartext_buf_len = free_size - ciphertext_buf_len; + + // Recoup `partially_read_buffer space`. This is necessary because it is assumed + // below that `frag0` is big enough to hold at least one record. + limitedOverlapCopy(c.partially_read_buffer[0..c.partial_ciphertext_end], c.partial_ciphertext_idx); + c.partial_ciphertext_end -= c.partial_ciphertext_idx; + c.partial_ciphertext_idx = 0; + c.partial_cleartext_idx = 0; const first_iov = c.partially_read_buffer[c.partial_ciphertext_end..]; var ask_iovecs_buf: [2]std.os.iovec = .{