]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
crypto/x509-utils: Check for error from gnutls_x509_crt_init()
authorPeter Maydell <peter.maydell@linaro.org>
Thu, 10 Jul 2025 14:44:17 +0000 (15:44 +0100)
committerDaniel P. Berrangé <berrange@redhat.com>
Wed, 16 Jul 2025 10:27:30 +0000 (11:27 +0100)
Coverity notes that in qcrypto_get_x509_cert_fingerprint() we
call gnutls_x509_crt_init() but don't check for an error return.
Add the missing check.

Coverity: CID 1593155
Fixes: 10a1d34fc0d ("crypto: Introduce x509 utils")
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
crypto/x509-utils.c

index 8bad00a51b867082df1fa324acec7b127f14c67c..39bb6d4d8c3f70994c0a05a0c34939c4ab2a2c73 100644 (file)
@@ -46,7 +46,11 @@ int qcrypto_get_x509_cert_fingerprint(uint8_t *cert, size_t size,
         return -1;
     }
 
-    gnutls_x509_crt_init(&crt);
+    if (gnutls_x509_crt_init(&crt) < 0) {
+        error_setg(errp, "Unable to initialize certificate: %s",
+                   gnutls_strerror(ret));
+        return -1;
+    }
 
     if (gnutls_x509_crt_import(crt, &datum, GNUTLS_X509_FMT_PEM) != 0) {
         error_setg(errp, "Failed to import certificate");