Skip to content

Commit

Permalink
crypto: avoid leak of ctx when bad cipher mode is given
Browse files Browse the repository at this point in the history
Fixes: Coverity CID 1546884
Reviewed-by: Peter Maydell <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Signed-off-by: Daniel P. Berrangé <[email protected]>
(cherry picked from commit 586ac2c)
Signed-off-by: Michael Tokarev <[email protected]>
  • Loading branch information
berrange authored and Michael Tokarev committed Sep 25, 2024
1 parent 0e8f3eb commit 3148a16
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions crypto/cipher-nettle.c.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 3148a16

Please sign in to comment.