aboutsummaryrefslogtreecommitdiff
path: root/crypto/cipher-nettle.c.inc
diff options
context:
space:
mode:
authorDaniel P. Berrangé <berrange@redhat.com>2024-06-10 10:26:18 +0100
committerDaniel P. Berrangé <berrange@redhat.com>2024-09-09 15:13:38 +0100
commit586ac2c67d707c2588766c5195d94fa553cc25af (patch)
tree590acec0a36cf76bbff14382d272b4fa388bec79 /crypto/cipher-nettle.c.inc
parentebe0302ac822da214f347f6cc37a73139660bed8 (diff)
downloadqemu-586ac2c67d707c2588766c5195d94fa553cc25af.zip
qemu-586ac2c67d707c2588766c5195d94fa553cc25af.tar.gz
qemu-586ac2c67d707c2588766c5195d94fa553cc25af.tar.bz2
crypto: avoid leak of ctx when bad cipher mode is given
Fixes: Coverity CID 1546884 Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Diffstat (limited to 'crypto/cipher-nettle.c.inc')
-rw-r--r--crypto/cipher-nettle.c.inc7
1 files changed, 5 insertions, 2 deletions
diff --git a/crypto/cipher-nettle.c.inc b/crypto/cipher-nettle.c.inc
index 42b39e1..766de03 100644
--- a/crypto/cipher-nettle.c.inc
+++ b/crypto/cipher-nettle.c.inc
@@ -734,16 +734,19 @@ static QCryptoCipher *qcrypto_cipher_ctx_new(QCryptoCipherAlgorithm alg,
#ifdef CONFIG_CRYPTO_SM4
case QCRYPTO_CIPHER_ALG_SM4:
{
- QCryptoNettleSm4 *ctx = g_new0(QCryptoNettleSm4, 1);
+ QCryptoNettleSm4 *ctx;
+ const QCryptoCipherDriver *drv;
switch (mode) {
case QCRYPTO_CIPHER_MODE_ECB:
- ctx->base.driver = &qcrypto_nettle_sm4_driver_ecb;
+ drv = &qcrypto_nettle_sm4_driver_ecb;
break;
default:
goto bad_cipher_mode;
}
+ ctx = g_new0(QCryptoNettleSm4, 1);
+ ctx->base.driver = drv;
sm4_set_encrypt_key(&ctx->key[0], key);
sm4_set_decrypt_key(&ctx->key[1], key);