]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
crypto/cmp/cmp_genm.c: avoid strcat() in get_genm_itav()
authorEugene Syromiatnikov <esyr@openssl.org>
Tue, 19 May 2026 07:18:23 +0000 (09:18 +0200)
committerEugene Syromiatnikov <esyr@openssl.org>
Tue, 26 May 2026 14:54:12 +0000 (16:54 +0200)
There is no need to use strcat() there, as it concatenates into a string
that is used in a format string anyway.  Put the literal prefix
into the format string and avoid literal string copying.

Fixes: d477484d33b7 "CMP: add support for genm/genp messages with id-it-caCerts"
Signed-off-by: Eugene Syromiatnikov <esyr@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.foundation>
Reviewed-by: Nikola Pajkovsky <nikolap@openssl.org>
Reviewed-by: Bob Beck <beck@openssl.org>
Reviewed-by: David von Oheimb <david.von.oheimb@siemens.com>
MergeDate: Tue May 26 14:54:19 2026
(Merged from https://github.com/openssl/openssl/pull/31230)

crypto/cmp/cmp_genm.c

index 86bad3a7445fe1dbb88e538cc2c143f33043668a..905927554fa96414494206fe651ac694553ca2a2 100644 (file)
@@ -133,8 +133,7 @@ static OSSL_CMP_ITAV *get_genm_itav(OSSL_CMP_CTX *ctx,
     for (i = 0; i < n; i++) {
         OSSL_CMP_ITAV *itav = sk_OSSL_CMP_ITAV_shift(itavs);
         ASN1_OBJECT *obj = OSSL_CMP_ITAV_get0_type(itav);
-        char name[128] = "genp contains InfoType '";
-        size_t offset = strlen(name);
+        char name[128];
 
         if (OBJ_obj2nid(obj) == expected) {
             for (i++; i < n; i++)
@@ -143,9 +142,11 @@ static OSSL_CMP_ITAV *get_genm_itav(OSSL_CMP_CTX *ctx,
             return itav;
         }
 
-        if (OBJ_obj2txt(name + offset, (int)(sizeof(name) - offset), obj, 0) < 0)
-            strcat(name, "<unknown>");
-        ossl_cmp_log2(WARN, ctx, "%s' while expecting 'id-it-%s'", name, desc);
+        if (OBJ_obj2txt(name, sizeof(name), obj, 0) < 0)
+            name[0] = '\0';
+        ossl_cmp_log2(WARN, ctx,
+            "genp contains InfoType '%s' while expecting 'id-it-%s'",
+            name[0] == '\0' ? "<unknown>" : name, desc);
         OSSL_CMP_ITAV_free(itav);
     }
     ERR_raise_data(ERR_LIB_CMP, CMP_R_INVALID_GENP,