From e6b033a3fc132c9d999cfb39efe0b83e7000a447 Mon Sep 17 00:00:00 2001 From: Stephan Bosch Date: Sat, 20 Nov 2021 14:37:16 +0100 Subject: [PATCH] imap-login: imap-proxy - Fix parsing REFERRAL response with IPv6 URL. --- src/imap-login/imap-proxy.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/imap-login/imap-proxy.c b/src/imap-login/imap-proxy.c index cbf4100684..2c62b5e9c5 100644 --- a/src/imap-login/imap-proxy.c +++ b/src/imap-login/imap-proxy.c @@ -262,16 +262,30 @@ auth_resp_code_parse_referral(struct client *client, const char *resp, const char **userhostport_r) { struct imap_url *url; - const char *error; + const char *end, *error; if (strncasecmp(resp, "REFERRAL ", 9) != 0) return FALSE; - if (imap_url_parse(resp + 9, NULL, 0, &url, &error) < 0) { + if (imap_url_parse_prefix(resp + 9, NULL, 0, &end, &url, &error) < 0) { e_debug(login_proxy_get_event(client->login_proxy), "Couldn't parse REFERRAL response '%s': %s", str_sanitize(resp, 160), error); return FALSE; } + if (*end == '\0') { + e_debug(login_proxy_get_event(client->login_proxy), + "Couldn't parse REFERRAL response '%s': " + "Premature end of response line (expected ']')", + str_sanitize(resp, 160)); + return FALSE; + } + if (*end != ']') { + e_debug(login_proxy_get_event(client->login_proxy), + "Couldn't parse REFERRAL response '%s': " + "Invalid character %s in URL", + str_sanitize(resp, 160), uri_char_sanitize(*end)); + return FALSE; + } string_t *str = t_str_new(128); if (url->userid != NULL) -- 2.47.3