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> (cherry picked from commit 586ac2c67d707c2588766c5195d94fa553cc25af) Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
This commit is contained in:
parent
0e8f3eb43f
commit
3148a16b30
@ -734,16 +734,19 @@ static QCryptoCipher *qcrypto_cipher_ctx_new(QCryptoCipherAlgorithm alg,
|
|||||||
#ifdef CONFIG_CRYPTO_SM4
|
#ifdef CONFIG_CRYPTO_SM4
|
||||||
case QCRYPTO_CIPHER_ALG_SM4:
|
case QCRYPTO_CIPHER_ALG_SM4:
|
||||||
{
|
{
|
||||||
QCryptoNettleSm4 *ctx = g_new0(QCryptoNettleSm4, 1);
|
QCryptoNettleSm4 *ctx;
|
||||||
|
const QCryptoCipherDriver *drv;
|
||||||
|
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case QCRYPTO_CIPHER_MODE_ECB:
|
case QCRYPTO_CIPHER_MODE_ECB:
|
||||||
ctx->base.driver = &qcrypto_nettle_sm4_driver_ecb;
|
drv = &qcrypto_nettle_sm4_driver_ecb;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
goto bad_cipher_mode;
|
goto bad_cipher_mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ctx = g_new0(QCryptoNettleSm4, 1);
|
||||||
|
ctx->base.driver = drv;
|
||||||
sm4_set_encrypt_key(&ctx->key[0], key);
|
sm4_set_encrypt_key(&ctx->key[0], key);
|
||||||
sm4_set_decrypt_key(&ctx->key[1], key);
|
sm4_set_decrypt_key(&ctx->key[1], key);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user