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>
This commit is contained in:
parent
d078da86d6
commit
bbd40a0e31
@ -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));
|
||||
|
Loading…
Reference in New Issue
Block a user