summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorDaniel P. Berrangé <berrange@redhat.com>2024-10-30 10:08:12 +0000
committerDaniel P. Berrangé <berrange@redhat.com>2024-11-05 18:37:18 +0000
commitbbd40a0e316bb06e1320d71fa3be7e2f3d62c7a9 (patch)
tree796b53a3b76b002370924afbe8ad2faf1edbbd35
parentd078da86d61cf0f188cd099bef9b7b2dcfeba5a7 (diff)
downloadfocaccia-qemu-bbd40a0e316bb06e1320d71fa3be7e2f3d62c7a9.tar.gz
focaccia-qemu-bbd40a0e316bb06e1320d71fa3be7e2f3d62c7a9.zip
crypto: fix error check on gcry_md_open
Gcrypt does not return negative values on error, it returns non-zero
values. This caused QEMU not to detect failure to open an unsupported
hash, resulting in a later crash trying to use a NULL context.

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
-rw-r--r--crypto/hash-gcrypt.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/crypto/hash-gcrypt.c b/crypto/hash-gcrypt.c
index f04a9f553c..476b748195 100644
--- a/crypto/hash-gcrypt.c
+++ b/crypto/hash-gcrypt.c
@@ -52,7 +52,7 @@ static
 QCryptoHash *qcrypto_gcrypt_hash_new(QCryptoHashAlgo alg, Error **errp)
 {
     QCryptoHash *hash;
-    int ret;
+    gcry_error_t ret;
 
     hash = g_new(QCryptoHash, 1);
     hash->alg = alg;
@@ -60,7 +60,7 @@ QCryptoHash *qcrypto_gcrypt_hash_new(QCryptoHashAlgo alg, Error **errp)
 
     ret = gcry_md_open((gcry_md_hd_t *) hash->opaque,
                        qcrypto_hash_alg_map[alg], 0);
-    if (ret < 0) {
+    if (ret != 0) {
         error_setg(errp,
                    "Unable to initialize hash algorithm: %s",
                    gcry_strerror(ret));