Fix interaction between SSL_stateless() and SSL_clear()
authorMatt Caswell <matt@openssl.org>
Thu, 28 Sep 2017 12:23:49 +0000 (13:23 +0100)
committerMatt Caswell <matt@openssl.org>
Wed, 24 Jan 2018 18:02:36 +0000 (18:02 +0000)
Reviewed-by: Ben Kaduk <kaduk@mit.edu>
(Merged from https://github.com/openssl/openssl/pull/4435)

ssl/ssl_lib.c
ssl/statem/statem.c

index 4e2dae0ee89b095669f8b5ef747284461a101022..1daa348f9ca341ecfa0fd7041865af882afde0d6 100644 (file)
@@ -590,6 +590,7 @@ int SSL_clear(SSL *s)
     OPENSSL_free(s->psksession_id);
     s->psksession_id = NULL;
     s->psksession_id_len = 0;
     OPENSSL_free(s->psksession_id);
     s->psksession_id = NULL;
     s->psksession_id_len = 0;
+    s->hello_retry_request = 0;
 
     s->error = 0;
     s->hit = 0;
 
     s->error = 0;
     s->hit = 0;
index 29660d59c422d811576bd8d3f546158d09f81403..45cb9ab092e6d74de2ef4b93405341705fab4494 100644 (file)
@@ -311,7 +311,11 @@ static int state_machine(SSL *s, int server)
 
     st->in_handshake++;
     if (!SSL_in_init(s) || SSL_in_before(s)) {
 
     st->in_handshake++;
     if (!SSL_in_init(s) || SSL_in_before(s)) {
-        if (!SSL_clear(s))
+        /*
+         * If we are stateless then we already called SSL_clear() - don't do
+         * it again and clear the STATELESS flag itself.
+         */
+        if ((s->s3->flags & TLS1_FLAGS_STATELESS) == 0 && !SSL_clear(s))
             return -1;
     }
 #ifndef OPENSSL_NO_SCTP
             return -1;
     }
 #ifndef OPENSSL_NO_SCTP