mirror of
https://github.com/cuberite/polarssl.git
synced 2025-10-02 10:00:47 -04:00
Move initialisation in test to before first test
Calling mbedtls_cipher_free() on a context that was not initialised is dangerous, and this could happen if the first test in check_set_padding() failed. Signed-off-by: Paul Elliott <paul.elliott@arm.com>
This commit is contained in:
parent
c6d633ffbc
commit
3bda79ba9f
@ -1218,6 +1218,8 @@ void check_set_padding(int cipher_id)
|
|||||||
const mbedtls_cipher_info_t *cipher_info;
|
const mbedtls_cipher_info_t *cipher_info;
|
||||||
size_t keylen = 0;
|
size_t keylen = 0;
|
||||||
|
|
||||||
|
mbedtls_cipher_init(&ctx);
|
||||||
|
|
||||||
cipher_info = mbedtls_cipher_info_from_type(cipher_id);
|
cipher_info = mbedtls_cipher_info_from_type(cipher_id);
|
||||||
|
|
||||||
if (cipher_info->mode != MBEDTLS_MODE_CBC) {
|
if (cipher_info->mode != MBEDTLS_MODE_CBC) {
|
||||||
@ -1228,8 +1230,6 @@ void check_set_padding(int cipher_id)
|
|||||||
TEST_CALLOC(key, keylen/8);
|
TEST_CALLOC(key, keylen/8);
|
||||||
memset(key, 0, keylen/8);
|
memset(key, 0, keylen/8);
|
||||||
|
|
||||||
mbedtls_cipher_init(&ctx);
|
|
||||||
|
|
||||||
TEST_EQUAL(0, mbedtls_cipher_setup(&ctx, cipher_info));
|
TEST_EQUAL(0, mbedtls_cipher_setup(&ctx, cipher_info));
|
||||||
|
|
||||||
TEST_EQUAL(0, mbedtls_cipher_setkey(&ctx, key, keylen,
|
TEST_EQUAL(0, mbedtls_cipher_setkey(&ctx, key, keylen,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user