From 9ebdcffef4d1841dc2e81f41c25ad200ac91e049 Mon Sep 17 00:00:00 2001 From: Mohammad Azim Khan Date: Mon, 6 Aug 2018 11:48:06 +0100 Subject: [PATCH] Fix Wformat-overflow warning in ssl_mail_client.c sprintf( (char *) buf, "%s\r\n", base ); Above code generates Wformat-overflow warning since both buf and base are of same size. buf should be sizeof( base ) + characters added in the format. In this case format 2 bytes for "\r\n". --- programs/ssl/ssl_mail_client.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/programs/ssl/ssl_mail_client.c b/programs/ssl/ssl_mail_client.c index d3b569cb0..16cedfe94 100644 --- a/programs/ssl/ssl_mail_client.c +++ b/programs/ssl/ssl_mail_client.c @@ -356,9 +356,15 @@ int main( int argc, char *argv[] ) int ret = 1, len; int exit_code = MBEDTLS_EXIT_FAILURE; mbedtls_net_context server_fd; - unsigned char buf[1024]; #if defined(MBEDTLS_BASE64_C) unsigned char base[1024]; + /* buf is used as the destination buffer for printing base with the format: + * "%s\r\n". Hence, the size of buf should be at least the size of base + * plus 2 bytes for the \r and \n characters. + */ + unsigned char buf[sizeof( base ) + 2]; +#else + unsigned char buf[1024]; #endif char hostname[32]; const char *pers = "ssl_mail_client";