summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/evp/evp_lib.c
diff options
context:
space:
mode:
authortb <>2023-11-18 09:37:15 +0000
committertb <>2023-11-18 09:37:15 +0000
commitcf1d9118861fb5ec267ff356834308151562d92d (patch)
tree6a57455fb90dc2e6329a93bfd6f50f475ffbf84e /src/lib/libcrypto/evp/evp_lib.c
parentc6a53967a0008fba21f8effe5960629cad4d4572 (diff)
downloadopenbsd-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/evp_lib.c')
-rw-r--r--src/lib/libcrypto/evp/evp_lib.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/lib/libcrypto/evp/evp_lib.c b/src/lib/libcrypto/evp/evp_lib.c
index f4e46aea41..55573b21db 100644
--- a/src/lib/libcrypto/evp/evp_lib.c
+++ b/src/lib/libcrypto/evp/evp_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: evp_lib.c,v 1.28 2023/09/28 11:29:10 tb Exp $ */ 1/* $OpenBSD: evp_lib.c,v 1.29 2023/11/18 09:37:15 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -98,16 +98,16 @@ int
98EVP_CIPHER_get_asn1_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type) 98EVP_CIPHER_get_asn1_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
99{ 99{
100 int i = 0; 100 int i = 0;
101 unsigned int l; 101 int l;
102 102
103 if (type != NULL) { 103 if (type != NULL) {
104 l = EVP_CIPHER_CTX_iv_length(c); 104 l = EVP_CIPHER_CTX_iv_length(c);
105 if (l > sizeof(c->iv)) { 105 if (l < 0 || l > sizeof(c->iv)) {
106 EVPerror(EVP_R_IV_TOO_LARGE); 106 EVPerror(EVP_R_IV_TOO_LARGE);
107 return 0; 107 return 0;
108 } 108 }
109 i = ASN1_TYPE_get_octetstring(type, c->oiv, l); 109 i = ASN1_TYPE_get_octetstring(type, c->oiv, l);
110 if (i != (int)l) 110 if (i != l)
111 return (-1); 111 return (-1);
112 else if (i > 0) 112 else if (i > 0)
113 memcpy(c->iv, c->oiv, l); 113 memcpy(c->iv, c->oiv, l);
@@ -119,11 +119,11 @@ int
119EVP_CIPHER_set_asn1_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type) 119EVP_CIPHER_set_asn1_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
120{ 120{
121 int i = 0; 121 int i = 0;
122 unsigned int j; 122 int j;
123 123
124 if (type != NULL) { 124 if (type != NULL) {
125 j = EVP_CIPHER_CTX_iv_length(c); 125 j = EVP_CIPHER_CTX_iv_length(c);
126 if (j > sizeof(c->iv)) { 126 if (j < 0 || j > sizeof(c->iv)) {
127 EVPerror(EVP_R_IV_TOO_LARGE); 127 EVPerror(EVP_R_IV_TOO_LARGE);
128 return 0; 128 return 0;
129 } 129 }