From: Daniel P. Berrangé Date: Fri, 11 Jul 2025 12:21:34 +0000 (+0100) Subject: crypto: switch to newer gnutls API for distinguished name X-Git-Tag: v10.2.0-rc1~44^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3b3257b00fd256b8704db13373f4fa9c8bc40342;p=thirdparty%2Fqemu.git crypto: switch to newer gnutls API for distinguished name The new API automatically allocates the right amount of memory to hold the distinguished name, avoiding the need to loop and realloc. Reviewed-by: Eric Blake Signed-off-by: Daniel P. Berrangé --- diff --git a/crypto/tlssession.c b/crypto/tlssession.c index 8c0bf457ad..92fe4f0380 100644 --- a/crypto/tlssession.c +++ b/crypto/tlssession.c @@ -409,20 +409,14 @@ qcrypto_tls_session_check_certificate(QCryptoTLSSession *session, } if (i == 0) { - size_t dnameSize = 1024; - session->peername = g_malloc(dnameSize); - requery: - ret = gnutls_x509_crt_get_dn(cert, session->peername, &dnameSize); + gnutls_datum_t dname = {}; + ret = gnutls_x509_crt_get_dn2(cert, &dname); if (ret < 0) { - if (ret == GNUTLS_E_SHORT_MEMORY_BUFFER) { - session->peername = g_realloc(session->peername, - dnameSize); - goto requery; - } error_setg(errp, "Cannot get client distinguished name: %s", gnutls_strerror(ret)); goto error; } + session->peername = (char *)g_steal_pointer(&dname.data); if (session->authzid) { bool allow;