Modify ssl_handshake_hash to call SSLfatal
authorTrev Larock <tlarock@juniper.net>
Fri, 28 May 2021 12:54:44 +0000 (12:54 +0000)
committerTomas Mraz <tomas@openssl.org>
Tue, 1 Jun 2021 14:43:43 +0000 (16:43 +0200)
When EVP_MD_CTX_new fails call SSLfatal before the goto err.
This resolves a state machine issue on the out of memory condition.

Fixes #15491.
CLA: trivial

Reviewed-by: Ben Kaduk <kaduk@mit.edu>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15520)

ssl/ssl_lib.c

index c8ab4a66a0ec0bdaadd9ba0443182deb0427618f..063134015a1937a0ff7fb053beef4145f73265c8 100644 (file)
@@ -4773,8 +4773,10 @@ int ssl_handshake_hash(SSL *s, unsigned char *out, size_t outlen,
     }
 
     ctx = EVP_MD_CTX_new();
-    if (ctx == NULL)
+    if (ctx == NULL) {
+        SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
         goto err;
+    }
 
     if (!EVP_MD_CTX_copy_ex(ctx, hdgst)
         || EVP_DigestFinal_ex(ctx, out, NULL) <= 0) {