Skip to content

Commit ca752c6

Browse files
ianicandrewrk
authored andcommitted
tls.Client: fix out of bounds panic
When calculating how much ciphertext from the stream can fit into user and internal buffers we should also take into account ciphertext data which are already in internal buffer. Fixes: 15226 Tested with [this](#15226 (comment)). Using client with different read buffers until I, hopefully, understood what is happening. Not relevant to this fix, but this [part](https://github.com/ziglang/zig/blob/95d9292a7a09ed883e65510ec054619747315c48/lib/std/crypto/tls/Client.zig#L988-L991) is still mystery to me. Why we don't use free_size in buf_cap calculation. Seems like rudiment from previous implementation without iovec.
1 parent 80d7e26 commit ca752c6

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/std/crypto/tls/Client.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,7 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.posix.iove
10121012
// Cleartext capacity of output buffer, in records. Minimum one full record.
10131013
const buf_cap = @max(cleartext_buf_len / max_ciphertext_len, 1);
10141014
const wanted_read_len = buf_cap * (max_ciphertext_len + tls.record_header_len);
1015-
const ask_len = @max(wanted_read_len, cleartext_stack_buffer.len);
1015+
const ask_len = @max(wanted_read_len, cleartext_stack_buffer.len) - c.partial_ciphertext_end;
10161016
const ask_iovecs = limitVecs(&ask_iovecs_buf, ask_len);
10171017
const actual_read_len = try stream.readv(ask_iovecs);
10181018
if (actual_read_len == 0) {

0 commit comments

Comments
 (0)