When selecting a method ensure we use the correct client/server version
authorMatt Caswell <matt@openssl.org>
Thu, 18 Jan 2024 12:07:27 +0000 (12:07 +0000)
committerMatt Caswell <matt@openssl.org>
Wed, 31 Jan 2024 10:10:55 +0000 (10:10 +0000)
Using the client one when the server once should be used could cause a
later call to SSL_set_accept_state() to unexpectedly fail.

Reviewed-by: Hugo Landau <hlandau@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/23256)

ssl/statem/statem_lib.c

index b16864606b502f4089046a3652912cebf2828dde..7ef74b1f69b8275b12377cc01065dc445778c641 100644 (file)
@@ -1977,14 +1977,17 @@ int ssl_version_supported(const SSL_CONNECTION *s, int version,
     for (vent = table;
          vent->version != 0 && ssl_version_cmp(s, version, vent->version) <= 0;
          ++vent) {
-        if (vent->cmeth != NULL
+        const SSL_METHOD *(*thismeth)(void) = s->server ? vent->smeth
+                                                        : vent->cmeth;
+
+        if (thismeth != NULL
                 && ssl_version_cmp(s, version, vent->version) == 0
-                && ssl_method_error(s, vent->cmeth()) == 0
+                && ssl_method_error(s, thismeth()) == 0
                 && (!s->server
                     || version != TLS1_3_VERSION
                     || is_tls13_capable(s))) {
             if (meth != NULL)
-                *meth = vent->cmeth();
+                *meth = thismeth();
             return 1;
         }
     }