Make alert sending function re-entrant
Fixes #1916
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
diff --git a/library/ssl_msg.c b/library/ssl_msg.c
index 4eac24b..051e4b0 100644
--- a/library/ssl_msg.c
+++ b/library/ssl_msg.c
@@ -4855,6 +4855,9 @@
if( ssl == NULL || ssl->conf == NULL )
return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA );
+ if( ssl->out_left != 0 )
+ return( mbedtls_ssl_flush_output( ssl ) );
+
MBEDTLS_SSL_DEBUG_MSG( 2, ( "=> send alert message" ) );
MBEDTLS_SSL_DEBUG_MSG( 3, ( "send alert level=%u message=%u", level, message ));
@@ -5714,9 +5717,6 @@
MBEDTLS_SSL_DEBUG_MSG( 2, ( "=> write close notify" ) );
- if( ssl->out_left != 0 )
- return( mbedtls_ssl_flush_output( ssl ) );
-
if( mbedtls_ssl_is_handshake_over( ssl ) == 1 )
{
if( ( ret = mbedtls_ssl_send_alert_message( ssl,