diff options
author | Matt Caswell <matt@openssl.org> | 2018-05-29 16:27:25 +0100 |
---|---|---|
committer | Matt Caswell <matt@openssl.org> | 2018-05-31 10:39:13 +0100 |
commit | bceae201b45fdbc7898adada6aebe2a1b6145009 (patch) | |
tree | 27147dd20a0c936444ef112f5ecdd889d6ad9ea5 /ssl/tls13_enc.c | |
parent | 1b3c89cd1e579aa8b9229498699ce54fa7986fa7 (diff) |
EVP_MD_size() can return an error
Fix some instances where we weren't checking the error return.
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6373)
Diffstat (limited to 'ssl/tls13_enc.c')
-rw-r--r-- | ssl/tls13_enc.c | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/ssl/tls13_enc.c b/ssl/tls13_enc.c index 1e6db92346..3fc8e96a89 100644 --- a/ssl/tls13_enc.c +++ b/ssl/tls13_enc.c @@ -129,6 +129,7 @@ int tls13_generate_secret(SSL *s, const EVP_MD *md, unsigned char *outsecret) { size_t mdlen, prevsecretlen; + int mdleni; int ret; EVP_PKEY_CTX *pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_HKDF, NULL); static const char derived_secret_label[] = "derived"; @@ -140,7 +141,14 @@ int tls13_generate_secret(SSL *s, const EVP_MD *md, return 0; } - mdlen = EVP_MD_size(md); + mdleni = EVP_MD_size(md); + /* Ensure cast to size_t is safe */ + if (!ossl_assert(mdleni >= 0)) { + SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS13_GENERATE_SECRET, + ERR_R_INTERNAL_ERROR); + return 0; + } + mdlen = (size_t)mdleni; if (insecret == NULL) { insecret = default_zeros; @@ -316,7 +324,16 @@ static int derive_secret_key_and_iv(SSL *s, int sending, const EVP_MD *md, { unsigned char key[EVP_MAX_KEY_LENGTH]; size_t ivlen, keylen, taglen; - size_t hashlen = EVP_MD_size(md); + int hashleni = EVP_MD_size(md); + size_t hashlen; + + /* Ensure cast to size_t is safe */ + if (!ossl_assert(hashleni >= 0)) { + SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_DERIVE_SECRET_KEY_AND_IV, + ERR_R_EVP_LIB); + goto err; + } + hashlen = (size_t)hashleni; if (!tls13_hkdf_expand(s, md, insecret, label, labellen, hash, hashlen, secret, hashlen)) { |