evp: fix coverity 1473380 Copy into fixed size buffer (STRING_OVERFLOW)
authorPauli <pauli@openssl.org>
Mon, 28 Jun 2021 22:26:11 +0000 (08:26 +1000)
committerPauli <pauli@openssl.org>
Wed, 30 Jun 2021 03:55:09 +0000 (13:55 +1000)
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15943)

crypto/evp/ctrl_params_translate.c

index 6998dcc6fc1679edb27dfde34d4477429577b13c..c532e57f8f6da976bc0edadb62f543a92bafff74 100644 (file)
@@ -1353,7 +1353,9 @@ 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 {
-            strcpy(ctx->name_buf, str_value_map[i].ptr);
+            strncpy(ctx->name_buf, str_value_map[i].ptr, sizeof(ctx->name_buf));
+            /* This won't truncate but it will quiet static analysers */
+            ctx->name_buf[sizeof(ctx->name_buf) - 1] = '\0';
         }
         ctx->p2 = ctx->name_buf;
         ctx->p1 = strlen(ctx->p2);