From daf4b2437f38bd104400517cf8ff2c8121813b1a Mon Sep 17 00:00:00 2001 From: Juergen Christ Date: Mon, 5 Jul 2021 09:48:53 +0200 Subject: [PATCH] Fix compile warning with GCC 11. When configured with strict warnings, GCC 11 complains about a possible stringop-translation: Config: /usr/bin/perl ./Configure enable-asan enable-ubsan enable-zlib-dynamic \ enable-unit-test enable-md2 enable-rc5 enable-buildtest-c++ \ enable-weak-ssl-ciphers enable-ssl3 enable-ssl3-method enable-fips -w \ --strict-warnings Warning: crypto/evp/ctrl_params_translate.c: In function 'fix_rsa_pss_saltlen': crypto/evp/ctrl_params_translate.c:1356:13: error: 'strncpy' specified bound 50 equals destination size [-Werror=stringop-truncation] 1356 | strncpy(ctx->name_buf, str_value_map[i].ptr, sizeof(ctx->name_buf)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Fix by copying one byte less than the buffer size. We anyway overwrite the last byte. Signed-off-by: Juergen Christ Reviewed-by: Paul Dale Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/15993) --- crypto/evp/ctrl_params_translate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crypto/evp/ctrl_params_translate.c b/crypto/evp/ctrl_params_translate.c index c532e57f8f6..4ea17380af9 100644 --- a/crypto/evp/ctrl_params_translate.c +++ b/crypto/evp/ctrl_params_translate.c @@ -1353,8 +1353,8 @@ static int fix_rsa_pss_saltlen(enum state state, if (i == OSSL_NELEM(str_value_map)) { BIO_snprintf(ctx->name_buf, sizeof(ctx->name_buf), "%d", ctx->p1); } else { - strncpy(ctx->name_buf, str_value_map[i].ptr, sizeof(ctx->name_buf)); /* This won't truncate but it will quiet static analysers */ + strncpy(ctx->name_buf, str_value_map[i].ptr, sizeof(ctx->name_buf) - 1); ctx->name_buf[sizeof(ctx->name_buf) - 1] = '\0'; } ctx->p2 = ctx->name_buf; -- 2.47.2