From 977dc4153d5170f92001f5cc6b0cde1cc23933a6 Mon Sep 17 00:00:00 2001 From: Stephan Bosch Date: Fri, 10 Mar 2023 04:12:20 +0100 Subject: [PATCH] lib-imap-urlauth: imap-urlauth - Make sure a host name is available in imap_urlauth_check_hostport(). Addresses FIXME. --- src/lib-imap-urlauth/imap-urlauth.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/lib-imap-urlauth/imap-urlauth.c b/src/lib-imap-urlauth/imap-urlauth.c index be67fe6bc3..a83e71a883 100644 --- a/src/lib-imap-urlauth/imap-urlauth.c +++ b/src/lib-imap-urlauth/imap-urlauth.c @@ -235,17 +235,24 @@ imap_urlauth_check_hostport(struct imap_urlauth_context *uctx, const struct imap_url *url, const char **client_error_r) { + struct imap_url url_full = *url; + + if (url_full.host.name == NULL) { + /* Not really supposed to happen, but we mend it anyway */ + i_assert(url_full.host.ip.family != 0); + url_full.host.name = net_ip2addr(&url_full.host.ip); + } + /* Validate host */ - /* FIXME: allow host ip/ip6 as well? */ if (strcmp(uctx->url_host, URL_HOST_ALLOW_ANY) != 0 && - strcmp(url->host.name, uctx->url_host) != 0) { + strcmp(url_full.host.name, uctx->url_host) != 0) { *client_error_r = "Invalid URL: Inappropriate host name"; return FALSE; } /* Validate port */ - if ((url->port == 0 && uctx->url_port != 143) || - (url->port != 0 && uctx->url_port != url->port)) { + if ((url_full.port == 0 && uctx->url_port != 143) || + (url_full.port != 0 && uctx->url_port != url->port)) { *client_error_r = "Invalid URL: Inappropriate server port"; return FALSE; } -- 2.47.3