]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: uri-util - Use IP over host name string in construction of URI host name.
authorStephan Bosch <stephan.bosch@open-xchange.com>
Tue, 23 Nov 2021 00:35:14 +0000 (01:35 +0100)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Mon, 17 Jan 2022 11:52:10 +0000 (13:52 +0200)
Both can be set when the URI was parsed earlier from a string or when the caller
sets both. There is never a valid case where these separate fields would yield a
completely different URI. Using the IP when available is necessary to make
sure IPv6 literals are output correctly; don't trust the caller to get it right.

src/lib/uri-util.c

index 79972f9829afcc8da8981d908839410dc6e5137a..8cd6d48170029c67be2ad612a0764a117c19bfcd 100644 (file)
@@ -1291,14 +1291,16 @@ void uri_append_host_ip(string_t *out, const struct ip_addr *host_ip)
 
 void uri_append_host(string_t *out, const struct uri_host *host)
 {
-       if (host->name != NULL) {
+       if (host->ip.family != 0)
+               uri_append_host_ip(out, &host->ip);
+       else {
+               i_assert(host->name != NULL);
                /* Assume IPv6 literal if starts with '['; avoid encoding */
                if (*host->name == '[')
                        str_append(out, host->name);
                else
                        uri_append_host_name(out, host->name);
-       } else
-               uri_append_host_ip(out, &host->ip);
+       }
 }
 
 void uri_append_port(string_t *out, in_port_t port)