mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-12-23 11:55:34 +00:00
Increment record sequence number in ssl_write_record()
Previously, the record sequence number was incremented at the end of each successful call to mbedtls_ssl_flush_output(), which works as long as there is precisely one such call for each outgoing record. When packing multiple records into a single datagram, this property is no longer true, and instead the increment of the record sequence number must happen after the record has been prepared, and not after it has been dispatched. This commit moves the code for incrementing the record sequence number from mbedtls_ssl_flush_output() to ssl_write_record().
This commit is contained in:
parent
198594709b
commit
04484621d0
|
@ -2648,7 +2648,7 @@ int mbedtls_ssl_fetch_input( mbedtls_ssl_context *ssl, size_t nb_want )
|
|||
int mbedtls_ssl_flush_output( mbedtls_ssl_context *ssl )
|
||||
{
|
||||
int ret;
|
||||
unsigned char *buf, i;
|
||||
unsigned char *buf;
|
||||
|
||||
MBEDTLS_SSL_DEBUG_MSG( 2, ( "=> flush output" ) );
|
||||
|
||||
|
@ -2691,16 +2691,6 @@ int mbedtls_ssl_flush_output( mbedtls_ssl_context *ssl )
|
|||
ssl->out_left -= ret;
|
||||
}
|
||||
|
||||
for( i = 8; i > ssl_ep_len( ssl ); i-- )
|
||||
if( ++ssl->out_ctr[i - 1] != 0 )
|
||||
break;
|
||||
|
||||
/* The loop goes to its end iff the counter is wrapping */
|
||||
if( i == ssl_ep_len( ssl ) )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "outgoing message counter would wrap" ) );
|
||||
return( MBEDTLS_ERR_SSL_COUNTER_WRAPPING );
|
||||
}
|
||||
|
||||
MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= flush output" ) );
|
||||
|
||||
|
@ -3236,6 +3226,16 @@ int mbedtls_ssl_write_record( mbedtls_ssl_context *ssl )
|
|||
|
||||
MBEDTLS_SSL_DEBUG_BUF( 4, "output record sent to network",
|
||||
ssl->out_hdr, mbedtls_ssl_hdr_len( ssl ) + ssl->out_msglen );
|
||||
for( i = 8; i > ssl_ep_len( ssl ); i-- )
|
||||
if( ++ssl->cur_out_ctr[i - 1] != 0 )
|
||||
break;
|
||||
|
||||
/* The loop goes to its end iff the counter is wrapping */
|
||||
if( i == ssl_ep_len( ssl ) )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "outgoing message counter would wrap" ) );
|
||||
return( MBEDTLS_ERR_SSL_COUNTER_WRAPPING );
|
||||
}
|
||||
}
|
||||
|
||||
if( ( ret = mbedtls_ssl_flush_output( ssl ) ) != 0 )
|
||||
|
|
Loading…
Reference in a new issue