45 lines
1.5 KiB
Diff
45 lines
1.5 KiB
Diff
|
|
From 0029172c2c57c18d6aef61070c2471f40de6bb45 Mon Sep 17 00:00:00 2001
|
||
|
|
From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= <berrange@redhat.com>
|
||
|
|
Date: Wed, 30 Oct 2024 10:08:12 +0000
|
||
|
|
Subject: [PATCH] crypto: fix error check on gcry_md_open
|
||
|
|
MIME-Version: 1.0
|
||
|
|
Content-Type: text/plain; charset=UTF-8
|
||
|
|
Content-Transfer-Encoding: 8bit
|
||
|
|
|
||
|
|
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>
|
||
|
|
Signed-off-by: cheliequan <cheliequan@inspur.com>
|
||
|
|
---
|
||
|
|
crypto/hash-gcrypt.c | 4 ++--
|
||
|
|
1 file changed, 2 insertions(+), 2 deletions(-)
|
||
|
|
|
||
|
|
diff --git a/crypto/hash-gcrypt.c b/crypto/hash-gcrypt.c
|
||
|
|
index d3bdfe5633..bf5d7ff9ba 100644
|
||
|
|
--- a/crypto/hash-gcrypt.c
|
||
|
|
+++ b/crypto/hash-gcrypt.c
|
||
|
|
@@ -56,7 +56,7 @@ qcrypto_gcrypt_hash_bytesv(QCryptoHashAlgorithm alg,
|
||
|
|
size_t *resultlen,
|
||
|
|
Error **errp)
|
||
|
|
{
|
||
|
|
- int i, ret;
|
||
|
|
+ gcry_error_t ret;
|
||
|
|
gcry_md_hd_t md;
|
||
|
|
unsigned char *digest;
|
||
|
|
|
||
|
|
@@ -69,7 +69,7 @@ qcrypto_gcrypt_hash_bytesv(QCryptoHashAlgorithm alg,
|
||
|
|
|
||
|
|
ret = gcry_md_open(&md, qcrypto_hash_alg_map[alg], 0);
|
||
|
|
|
||
|
|
- if (ret < 0) {
|
||
|
|
+ if (ret != 0) {
|
||
|
|
error_setg(errp,
|
||
|
|
"Unable to initialize hash algorithm: %s",
|
||
|
|
gcry_strerror(ret));
|
||
|
|
--
|
||
|
|
2.41.0.windows.1
|
||
|
|
|