From 1097b34022a416ee180c13dd7a84d3bcbbd85542 Mon Sep 17 00:00:00 2001 From: Hanno Becker Date: Wed, 15 Aug 2018 14:09:41 +0100 Subject: [PATCH] Extract message-consuming code-path to separate function The first part of the function ssl_read_record_layer() was to mark the previous message as consumed. This commit moves the corresponding code-path to a separate static function ssl_consume_current_message(). --- library/ssl_tls.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/library/ssl_tls.c b/library/ssl_tls.c index b8f271527..23a5bddac 100644 --- a/library/ssl_tls.c +++ b/library/ssl_tls.c @@ -4283,6 +4283,9 @@ static void ssl_handshake_wrapup_free_hs_transform( mbedtls_ssl_context *ssl ); * RFC 6347 4.1.2.7) and continue reading until a valid record is found. * */ + +/* Helper functions for mbedtls_ssl_read_record(). */ +static int ssl_consume_current_message( mbedtls_ssl_context *ssl ); static int ssl_read_record_layer( mbedtls_ssl_context *ssl ); int mbedtls_ssl_read_record( mbedtls_ssl_context *ssl, @@ -4334,13 +4337,9 @@ int mbedtls_ssl_read_record( mbedtls_ssl_context *ssl, return( 0 ); } -static int ssl_read_record_layer( mbedtls_ssl_context *ssl ) +static int ssl_consume_current_message( mbedtls_ssl_context *ssl ) { - int ret; - /* - * Step A - * * Consume last content-layer message and potentially * update in_msglen which keeps track of the contents' * consumption state. @@ -4422,6 +4421,25 @@ static int ssl_read_record_layer( mbedtls_ssl_context *ssl ) ssl->in_msglen = 0; } + return( 0 ); +} + +static int ssl_read_record_layer( mbedtls_ssl_context *ssl ) +{ + int ret; + + /* + * Step A + * + * Consume last content-layer message and potentially + * update in_msglen which keeps track of the contents' + * consumption state. + */ + + ret = ssl_consume_current_message( ssl ); + if( ret != 0 ) + return( ret ); + /* * Step B *