diff options
author | Neil Horman <nhorman@openssl.org> | 2023-10-30 13:47:05 -0400 |
---|---|---|
committer | Matt Caswell <matt@openssl.org> | 2023-11-02 11:26:21 +0000 |
commit | fe26b6b4961b1d5a560b52463923f6fb014f5068 (patch) | |
tree | a35cfa3453325003509862eacbce2fb5135b4e54 /util | |
parent | 6874003e96b64b665acc20f65a5bcb3e4d315ce4 (diff) |
Fix quicserver binding when duplicate entries exist
In testing the quic demos, I found that the quicserver refused to start for me,
indicating an inability to bind a socket to listen on
The problem turned out to be that getaddrinfo on my system was returning
multiple entries, due to the fact that /etc/host maps the localhost host name to
both ipv4 (127.0.0.1) and ipv6 (::1), but returns the latter as an ipv4 mapped
address (specifying family == AF_INET)
It seems like the proper fix would be to modify the /etc/hosts file to not make
that mapping, and indeed that works. However, since several distribution ship
with this setup, it seems like it is worthwhile to manage it in the server code.
its also that some other application may be bound to a given address/port
leading to failure, which I think could be considered erroneous, as any failure
for the full addrinfo list in quicserver would lead to a complete failure
Fix this by modifying the create_dgram_bio function to count the number of
sockets is successfully binds/listens on, skipping any failures, and only exit
the application if the number of bound sockets is zero.
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/22559)
Diffstat (limited to 'util')
-rw-r--r-- | util/quicserver.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/util/quicserver.c b/util/quicserver.c index b80a5ce21a..b5c15806a3 100644 --- a/util/quicserver.c +++ b/util/quicserver.c @@ -94,23 +94,23 @@ static BIO *create_dgram_bio(int family, const char *hostname, const char *port) /* Start listening on the socket */ if (!BIO_listen(sock, BIO_ADDRINFO_address(ai), 0)) { BIO_closesocket(sock); - sock = -1; continue; } /* Set to non-blocking mode */ if (!BIO_socket_nbio(sock, 1)) { BIO_closesocket(sock); - sock = -1; continue; } + + break; /* stop searching if we found an addr */ } /* Free the address information resources we allocated earlier */ BIO_ADDRINFO_free(res); - /* If sock is -1 then we've been unable to connect to the server */ - if (sock == -1) + /* If we didn't bind any sockets, fail */ + if (ai == NULL) return NULL; /* Create a BIO to wrap the socket */ |