diff options
author | tb <> | 2023-11-18 09:37:15 +0000 |
---|---|---|
committer | tb <> | 2023-11-18 09:37:15 +0000 |
commit | cf1d9118861fb5ec267ff356834308151562d92d (patch) | |
tree | 6a57455fb90dc2e6329a93bfd6f50f475ffbf84e /src/lib/libcrypto/evp/e_aes.c | |
parent | c6a53967a0008fba21f8effe5960629cad4d4572 (diff) | |
download | openbsd-cf1d9118861fb5ec267ff356834308151562d92d.tar.gz openbsd-cf1d9118861fb5ec267ff356834308151562d92d.tar.bz2 openbsd-cf1d9118861fb5ec267ff356834308151562d92d.zip |
Check for negative IV length
A recent change in EVP_CIPHER_CTX_iv_length() made it possible in principle
that this function returns -1. This can only happen for an incorrectly set
up EVP_CIPHER. Still it is better form to check for negative lengths before
stuffing it into a memcpy().
It would probably be desirable to cap the iv_length to something large
enough. This can be done another time.
ok beck
Diffstat (limited to 'src/lib/libcrypto/evp/e_aes.c')
-rw-r--r-- | src/lib/libcrypto/evp/e_aes.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/lib/libcrypto/evp/e_aes.c b/src/lib/libcrypto/evp/e_aes.c index 3d357f0119..eb7f520282 100644 --- a/src/lib/libcrypto/evp/e_aes.c +++ b/src/lib/libcrypto/evp/e_aes.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: e_aes.c,v 1.54 2023/09/28 11:29:10 tb Exp $ */ | 1 | /* $OpenBSD: e_aes.c,v 1.55 2023/11/18 09:37:15 tb Exp $ */ |
2 | /* ==================================================================== | 2 | /* ==================================================================== |
3 | * Copyright (c) 2001-2011 The OpenSSL Project. All rights reserved. | 3 | * Copyright (c) 2001-2011 The OpenSSL Project. All rights reserved. |
4 | * | 4 | * |
@@ -2460,7 +2460,11 @@ aes_wrap_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | |||
2460 | } | 2460 | } |
2461 | 2461 | ||
2462 | if (iv != NULL) { | 2462 | if (iv != NULL) { |
2463 | memcpy(ctx->iv, iv, EVP_CIPHER_CTX_iv_length(ctx)); | 2463 | int iv_len = EVP_CIPHER_CTX_iv_length(ctx); |
2464 | |||
2465 | if (iv_len < 0 || iv_len > sizeof(ctx->iv)) | ||
2466 | return 0; | ||
2467 | memcpy(ctx->iv, iv, iv_len); | ||
2464 | wctx->iv = ctx->iv; | 2468 | wctx->iv = ctx->iv; |
2465 | } | 2469 | } |
2466 | 2470 | ||