Make BIO_do_connect() and friends handle multiple IP addresses
authorDr. David von Oheimb <David.von.Oheimb@siemens.com>
Thu, 28 May 2020 17:03:37 +0000 (19:03 +0200)
committerDr. David von Oheimb <David.von.Oheimb@siemens.com>
Mon, 1 Jun 2020 07:26:52 +0000 (09:26 +0200)
Backport of #11971

Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
(Merged from https://github.com/openssl/openssl/pull/11989)

crypto/bio/bss_conn.c

index dd43a406018ca82f9a367b6281c4545f587e7344..f4c6b85728f45ae9ad2880258d6b0b5e84db7829 100644 (file)
@@ -186,8 +186,17 @@ static int conn_state(BIO *b, BIO_CONNECT *c)
 
         case BIO_CONN_S_BLOCKED_CONNECT:
             i = BIO_sock_error(b->num);
-            if (i) {
+            if (i != 0) {
                 BIO_clear_retry_flags(b);
+                if ((c->addr_iter = BIO_ADDRINFO_next(c->addr_iter)) != NULL) {
+                    /*
+                     * if there are more addresses to try, do that first
+                     */
+                    BIO_closesocket(b->num);
+                    c->state = BIO_CONN_S_CREATE_SOCKET;
+                    ERR_clear_error();
+                    break;
+                }
                 SYSerr(SYS_F_CONNECT, i);
                 ERR_add_error_data(4,
                                    "hostname=", c->param_hostname,