]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
imap-login: imap-proxy - Fix parsing REFERRAL response with IPv6 URL.
authorStephan Bosch <stephan.bosch@open-xchange.com>
Sat, 20 Nov 2021 13:37:16 +0000 (14:37 +0100)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Mon, 17 Jan 2022 11:52:10 +0000 (13:52 +0200)
src/imap-login/imap-proxy.c

index cbf4100684b9562b691d0ba6efe27acd009a478a..2c62b5e9c597668b7186a3f7cd9fee6962becf1e 100644 (file)
@@ -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)