mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2026-11-10 07:10:12 +08:00
avoid -Wstringop-overflow when buiding with gcc11
Signed-off-by: Shawn Carey <shawn.carey@netfoundry.io>
This commit is contained in:
parent
7b81dcf90f
commit
69c5f5d81c
@ -6364,8 +6364,6 @@ static void ssl_calc_finished_tls_sha256(
|
||||
|
||||
#if defined(MBEDTLS_SHA512_C)
|
||||
|
||||
typedef int (*finish_sha384_t)(mbedtls_sha512_context*, unsigned char*);
|
||||
|
||||
static void ssl_calc_finished_tls_sha384(
|
||||
mbedtls_ssl_context *ssl, unsigned char *buf, int from )
|
||||
{
|
||||
@ -6373,12 +6371,6 @@ static void ssl_calc_finished_tls_sha384(
|
||||
const char *sender;
|
||||
mbedtls_sha512_context sha512;
|
||||
unsigned char padbuf[48];
|
||||
/*
|
||||
* For SHA-384, we can save 16 bytes by keeping padbuf 48 bytes long.
|
||||
* However, to avoid stringop-overflow warning in gcc, we have to cast
|
||||
* mbedtls_sha512_finish_ret().
|
||||
*/
|
||||
finish_sha384_t finish_sha384 = (finish_sha384_t)mbedtls_sha512_finish_ret;
|
||||
|
||||
mbedtls_ssl_session *session = ssl->session_negotiate;
|
||||
if( !session )
|
||||
@ -6404,8 +6396,19 @@ static void ssl_calc_finished_tls_sha384(
|
||||
sender = ( from == MBEDTLS_SSL_IS_CLIENT )
|
||||
? "client finished"
|
||||
: "server finished";
|
||||
|
||||
finish_sha384( &sha512, padbuf );
|
||||
/* mbedtls_sha512_finish_ret's output parameter is declared as a
|
||||
* 64-byte buffer, but sice we're using SHA-384, we know that the
|
||||
* output fits in 48 bytes. This is correct C, but GCC 11.1 warns
|
||||
* about it.
|
||||
*/
|
||||
#if defined(__GNUC__) && __GNUC__ >= 11
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wstringop-overflow"
|
||||
#endif
|
||||
mbedtls_sha512_finish_ret( &sha512, padbuf );
|
||||
#if defined(__GNUC__) && __GNUC__ >= 11
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
ssl->handshake->tls_prf( session->master, 48, sender,
|
||||
padbuf, 48, buf, len );
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user