]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
OpenSSL: Check EVP_CIPHER_CTX_set_padding() return value more consistently
authorJouni Malinen <j@w1.fi>
Sun, 17 Dec 2023 09:58:48 +0000 (11:58 +0200)
committerJouni Malinen <j@w1.fi>
Sun, 17 Dec 2023 09:58:48 +0000 (11:58 +0200)
Even though this function is documented to always return 1, be more
consistent in checking that to avoid warnings from static analyzers.

Signed-off-by: Jouni Malinen <j@w1.fi>
src/crypto/crypto_openssl.c

index 22f6ab4c18a8f9910227e5ea76d9778844d6a847..c6369e8ab39ee6d5f4ac30d2cc57338d5a35b069 100644 (file)
@@ -471,11 +471,11 @@ void * aes_encrypt_init(const u8 *key, size_t len)
        ctx = EVP_CIPHER_CTX_new();
        if (ctx == NULL)
                return NULL;
-       if (EVP_EncryptInit_ex(ctx, type, NULL, key, NULL) != 1) {
+       if (EVP_EncryptInit_ex(ctx, type, NULL, key, NULL) != 1 ||
+           EVP_CIPHER_CTX_set_padding(ctx, 0) != 1) {
                EVP_CIPHER_CTX_free(ctx);
                return NULL;
        }
-       EVP_CIPHER_CTX_set_padding(ctx, 0);
        return ctx;
 }
 
@@ -528,11 +528,11 @@ void * aes_decrypt_init(const u8 *key, size_t len)
        ctx = EVP_CIPHER_CTX_new();
        if (ctx == NULL)
                return NULL;
-       if (EVP_DecryptInit_ex(ctx, type, NULL, key, NULL) != 1) {
+       if (EVP_DecryptInit_ex(ctx, type, NULL, key, NULL) != 1 ||
+           EVP_CIPHER_CTX_set_padding(ctx, 0) != 1) {
                EVP_CIPHER_CTX_free(ctx);
                return NULL;
        }
-       EVP_CIPHER_CTX_set_padding(ctx, 0);
        return ctx;
 }