evp: fix Coverity 1485668 argument cannot be negative
authorPauli <pauli@openssl.org>
Sun, 6 Jun 2021 23:42:54 +0000 (09:42 +1000)
committerPauli <pauli@openssl.org>
Tue, 8 Jun 2021 09:32:17 +0000 (19:32 +1000)
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15635)

crypto/evp/e_bf.c

index 734e77f0a90d7f402a7a37c733e2882089407056..e3ff56875785f3d4298056372be84bed9e6477f2 100644 (file)
@@ -38,7 +38,11 @@ IMPLEMENT_BLOCK_CIPHER(bf, ks, BF, EVP_BF_KEY, NID_bf, 8, 16, 8, 64,
 static int bf_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
                        const unsigned char *iv, int enc)
 {
-    BF_set_key(&data(ctx)->ks, EVP_CIPHER_CTX_get_key_length(ctx), key);
+    int len = EVP_CIPHER_CTX_get_key_length(ctx);
+
+    if (len < 0)
+        return 0;
+    BF_set_key(&data(ctx)->ks, len, key);
     return 1;
 }