From bd70c8e77190f8f0498f60830c8ddac1d3958328 Mon Sep 17 00:00:00 2001 From: Hanno Becker Date: Fri, 12 Jul 2019 09:40:44 +0100 Subject: [PATCH] Move update of in_xxx fields in ssl_get_next_record() ssl_get_next_record() updates the legacy in_xxx fields in two places, once before record decryption and once after. Now that record decryption doesn't use or affect the in_xxx fields anymore, setting up the these legacy fields can entirely be moved to the end of ssl_get_next_record(), which is what this comit does. This commit solely moves existing code, but doesn't yet simplify the now partially redundant settings of the in_xxx fields. This will be done in a separate commit. --- library/ssl_tls.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/library/ssl_tls.c b/library/ssl_tls.c index 49a009dca..7e3b9ebae 100644 --- a/library/ssl_tls.c +++ b/library/ssl_tls.c @@ -5890,19 +5890,6 @@ static int ssl_get_next_record( mbedtls_ssl_context *ssl ) } } - /* Reset in pointers to default state for TLS/DTLS records, - * assuming no CID and no offset between record content and - * record plaintext. */ - ssl_update_in_pointers( ssl ); - - /* Setup internal message pointers from record structure. */ - ssl->in_msgtype = rec.type; -#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID) - ssl->in_len = ssl->in_cid + rec.cid_len; -#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */ - ssl->in_iv = ssl->in_msg = ssl->in_len + 2; - ssl->in_msglen = rec.data_len; - #if defined(MBEDTLS_SSL_PROTO_DTLS) if( MBEDTLS_SSL_TRANSPORT_IS_DTLS( ssl->conf->transport ) ) { @@ -5997,6 +5984,20 @@ static int ssl_get_next_record( mbedtls_ssl_context *ssl ) #endif /* MBEDTLS_SSL_PROTO_TLS */ } + + /* Reset in pointers to default state for TLS/DTLS records, + * assuming no CID and no offset between record content and + * record plaintext. */ + ssl_update_in_pointers( ssl ); + + /* Setup internal message pointers from record structure. */ + ssl->in_msgtype = rec.type; +#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID) + ssl->in_len = ssl->in_cid + rec.cid_len; +#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */ + ssl->in_iv = ssl->in_msg = ssl->in_len + 2; + ssl->in_msglen = rec.data_len; + /* The record content type may change during decryption, * so re-read it. */ ssl->in_msgtype = rec.type;