diff options
| author | kenjiro <> | 2026-08-21 02:23:33 +0000 |
|---|---|---|
| committer | kenjiro <> | 2026-08-21 02:23:33 +0000 |
| commit | aadc1d67e4c39bc3840c965d12277e1d7f68e948 (patch) | |
| tree | 7844562c788b1a87efcc7bf1cc8ef932c3c44dce /src | |
| parent | 70897123d5abbd10ccf1626cda82a140db125fc8 (diff) | |
| download | openbsd-aadc1d67e4c39bc3840c965d12277e1d7f68e948.tar.gz openbsd-aadc1d67e4c39bc3840c965d12277e1d7f68e948.tar.bz2 openbsd-aadc1d67e4c39bc3840c965d12277e1d7f68e948.zip | |
Allocate TLS 1.3 receive buffers lazily
The receive buffer is not used for records created for sending. Avoid
allocating a maximum-sized buffer in tls13_record_new() and instead
allocate a header-sized buffer when tls13_record_recv() is first called.
The buffer will grow as needed once the record length is known.
This avoids an unnecessary allocation for outgoing records and reduces
the initial allocation size for incoming records.
ok tb jsing
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/libssl/tls13_record.c | 21 |
1 files changed, 7 insertions, 14 deletions
diff --git a/src/lib/libssl/tls13_record.c b/src/lib/libssl/tls13_record.c index dbc835c546..0723fa3b0a 100644 --- a/src/lib/libssl/tls13_record.c +++ b/src/lib/libssl/tls13_record.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: tls13_record.c,v 1.10 2022/07/22 19:33:53 jsing Exp $ */ | 1 | /* $OpenBSD: tls13_record.c,v 1.11 2026/08/21 02:23:33 kenjiro Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2018, 2019 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2018, 2019 Joel Sing <jsing@openbsd.org> |
| 4 | * | 4 | * |
| @@ -32,19 +32,7 @@ struct tls13_record { | |||
| 32 | struct tls13_record * | 32 | struct tls13_record * |
| 33 | tls13_record_new(void) | 33 | tls13_record_new(void) |
| 34 | { | 34 | { |
| 35 | struct tls13_record *rec = NULL; | 35 | return calloc(1, sizeof(struct tls13_record)); |
| 36 | |||
| 37 | if ((rec = calloc(1, sizeof(struct tls13_record))) == NULL) | ||
| 38 | goto err; | ||
| 39 | if ((rec->buf = tls_buffer_new(TLS13_RECORD_MAX_LEN)) == NULL) | ||
| 40 | goto err; | ||
| 41 | |||
| 42 | return rec; | ||
| 43 | |||
| 44 | err: | ||
| 45 | tls13_record_free(rec); | ||
| 46 | |||
| 47 | return NULL; | ||
| 48 | } | 36 | } |
| 49 | 37 | ||
| 50 | void | 38 | void |
| @@ -129,6 +117,11 @@ tls13_record_recv(struct tls13_record *rec, tls_read_cb wire_read, | |||
| 129 | if (rec->data != NULL) | 117 | if (rec->data != NULL) |
| 130 | return TLS13_IO_FAILURE; | 118 | return TLS13_IO_FAILURE; |
| 131 | 119 | ||
| 120 | if (rec->buf == NULL) | ||
| 121 | rec->buf = tls_buffer_new(TLS13_RECORD_HEADER_LEN); | ||
| 122 | if (rec->buf == NULL) | ||
| 123 | return TLS13_IO_FAILURE; | ||
| 124 | |||
| 132 | if (rec->content_type == 0) { | 125 | if (rec->content_type == 0) { |
| 133 | if ((ret = tls_buffer_extend(rec->buf, | 126 | if ((ret = tls_buffer_extend(rec->buf, |
| 134 | TLS13_RECORD_HEADER_LEN, wire_read, wire_arg)) <= 0) | 127 | TLS13_RECORD_HEADER_LEN, wire_read, wire_arg)) <= 0) |
