summary refs log tree commit diff stats
path: root/crypto/x509-utils.c
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2025-07-10 15:44:17 +0100
committerDaniel P. Berrangé <berrange@redhat.com>2025-07-16 11:27:30 +0100
commit2183ab62512c6253293e83cce3970b0b42e65630 (patch)
treec698894533d23fc6747f4ac3b1dde974e3f8b7c0 /crypto/x509-utils.c
parent8fc3d63d685751734fb9c8c0284dc44a36a8e053 (diff)
downloadfocaccia-qemu-2183ab62512c6253293e83cce3970b0b42e65630.tar.gz
focaccia-qemu-2183ab62512c6253293e83cce3970b0b42e65630.zip
crypto/x509-utils: Check for error from gnutls_x509_crt_init()
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>
Diffstat (limited to 'crypto/x509-utils.c')
-rw-r--r--crypto/x509-utils.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/crypto/x509-utils.c b/crypto/x509-utils.c
index 8bad00a51b..39bb6d4d8c 100644
--- a/crypto/x509-utils.c
+++ b/crypto/x509-utils.c
@@ -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");