Skip to content

Commit

Permalink
tls_common.c: Align the calculation of maximal alignment value
Browse files Browse the repository at this point in the history
In tls_setup_write_buffer() and tls_setup_read_buffer() the calculation
is different. Make them the same.

Fixes openssl#25746

Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from openssl#25764)
  • Loading branch information
fwh-dc authored and t8m committed Oct 24, 2024
1 parent 3d3bb26 commit fc0e794
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions ssl/record/methods/tls_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ int tls_setup_write_buffer(OSSL_RECORD_LAYER *rl, size_t numwpipes,
size_t firstlen, size_t nextlen)
{
unsigned char *p;
size_t align = 0, headerlen;
size_t maxalign = 0, headerlen;
TLS_BUFFER *wb;
size_t currpipe;
size_t defltlen = 0;
Expand All @@ -160,10 +160,10 @@ int tls_setup_write_buffer(OSSL_RECORD_LAYER *rl, size_t numwpipes,
contenttypelen = 1;

#if defined(SSL3_ALIGN_PAYLOAD) && SSL3_ALIGN_PAYLOAD != 0
align = SSL3_ALIGN_PAYLOAD - 1;
maxalign = SSL3_ALIGN_PAYLOAD - 1;
#endif

defltlen = align + headerlen + rl->eivlen + rl->max_frag_len
defltlen = maxalign + headerlen + rl->eivlen + rl->max_frag_len
+ contenttypelen + SSL3_RT_SEND_MAX_ENCRYPTED_OVERHEAD;
#ifndef OPENSSL_NO_COMP
if (tls_allow_compression(rl))
Expand All @@ -175,7 +175,7 @@ int tls_setup_write_buffer(OSSL_RECORD_LAYER *rl, size_t numwpipes,
* always be 0 in these protocol versions
*/
if ((rl->options & SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS) == 0)
defltlen += headerlen + align + SSL3_RT_SEND_MAX_ENCRYPTED_OVERHEAD;
defltlen += headerlen + maxalign + SSL3_RT_SEND_MAX_ENCRYPTED_OVERHEAD;
}

wb = rl->wbuf;
Expand Down Expand Up @@ -229,7 +229,7 @@ static void tls_release_write_buffer(OSSL_RECORD_LAYER *rl)
int tls_setup_read_buffer(OSSL_RECORD_LAYER *rl)
{
unsigned char *p;
size_t len, align = 0, headerlen;
size_t len, maxalign = 0, headerlen;
TLS_BUFFER *b;

b = &rl->rbuf;
Expand All @@ -240,12 +240,12 @@ int tls_setup_read_buffer(OSSL_RECORD_LAYER *rl)
headerlen = SSL3_RT_HEADER_LENGTH;

#if defined(SSL3_ALIGN_PAYLOAD) && SSL3_ALIGN_PAYLOAD != 0
align = (-SSL3_RT_HEADER_LENGTH) & (SSL3_ALIGN_PAYLOAD - 1);
maxalign = SSL3_ALIGN_PAYLOAD - 1;
#endif

if (b->buf == NULL) {
len = rl->max_frag_len
+ SSL3_RT_MAX_ENCRYPTED_OVERHEAD + headerlen + align;
+ SSL3_RT_MAX_ENCRYPTED_OVERHEAD + headerlen + maxalign;
#ifndef OPENSSL_NO_COMP
if (tls_allow_compression(rl))
len += SSL3_RT_MAX_COMPRESSED_OVERHEAD;
Expand Down

0 comments on commit fc0e794

Please sign in to comment.