Mercurial > dovecot > core-2.2
changeset 18495:9024d226b813
uri-util: Allow empty host name in the generic URI syntax as specified in RFC 3986.
author | Stephan Bosch <stephan@rename-it.nl> |
---|---|
date | Sat, 25 Apr 2015 11:42:06 +0200 |
parents | 63224afb8c02 |
children | 5ae8cd8e42f7 |
files | src/lib-http/http-url.c src/lib-imap/imap-url.c src/lib/uri-util.c |
diffstat | 3 files changed, 26 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-http/http-url.c Sat Apr 25 11:42:06 2015 +0200 +++ b/src/lib-http/http-url.c Sat Apr 25 11:42:06 2015 +0200 @@ -37,6 +37,16 @@ if ((ret = uri_parse_authority(parser, &auth)) < 0) return FALSE; + if (auth.host_literal == NULL || *auth.host_literal == '\0') { + /* RFC 7230, Section 2.7.1: http URI Scheme + + A sender MUST NOT generate an "http" URI with an empty host + identifier. A recipient that processes such a URI reference MUST + reject it as invalid. + */ + parser->error = "HTTP URL does not allow empty host identifier"; + return FALSE; + } if (ret > 0) { if (auth.enc_userinfo != NULL) { const char *p;
--- a/src/lib-imap/imap-url.c Sat Apr 25 11:42:06 2015 +0200 +++ b/src/lib-imap/imap-url.c Sat Apr 25 11:42:06 2015 +0200 @@ -193,7 +193,14 @@ /* "//" iserver */ if ((ret = uri_parse_slashslash_authority(parser, &auth)) <= 0) return ret; - + if (auth.host_literal == NULL || *auth.host_literal == '\0') { + /* This situation is not documented anywhere, but it is not + currently useful either and potentially problematic if not + handled explicitly everywhere. So, it is denied hier for now. + */ + parser->error = "IMAP URL does not allow empty host identifier"; + return -1; + } /* iuserinfo = enc-user [iauth] / [enc-user] iauth */ if (auth.enc_userinfo != NULL) { const char *p, *uend;
--- a/src/lib/uri-util.c Sat Apr 25 11:42:06 2015 +0200 +++ b/src/lib/uri-util.c Sat Apr 25 11:42:06 2015 +0200 @@ -327,8 +327,6 @@ static int uri_parse_reg_name(struct uri_parser *parser, string_t *reg_name) { - int len = 0; - /* RFC 3986: * * reg-name = *( unreserved / pct-encoded / sub-delims ) @@ -345,7 +343,6 @@ if (ret > 0) { if (reg_name != NULL) str_append_c(reg_name, c); - len++; continue; } @@ -355,12 +352,11 @@ if (reg_name != NULL) str_append_c(reg_name, *parser->cur); parser->cur++; - len++; continue; } break; } - return len > 0 ? 1 : 0; + return 0; } #ifdef HAVE_IPV6 @@ -465,12 +461,11 @@ str_truncate(literal, 0); /* reg-name */ - if ((ret = uri_parse_reg_name(parser, literal)) != 0) { - if (ret > 0 && auth != NULL) { - auth->host_literal = t_strdup(str_c(literal)); - auth->have_host_ip = FALSE; - } - return ret; + if (uri_parse_reg_name(parser, literal) < 0) + return -1; + if (auth != NULL) { + auth->host_literal = t_strdup(str_c(literal)); + auth->have_host_ip = FALSE; } return 0; } @@ -537,16 +532,8 @@ } /* host */ - if ((ret = uri_parse_host(parser, auth)) <= 0) { - if (ret == 0) { - if (p == parser->end || *p == ':' || *p == '/') - parser->error = "Missing 'host' component"; - else - parser->error = "Invalid 'host' component"; - return -1; - } - return ret; - } + if (uri_parse_host(parser, auth) < 0) + return -1; /* [":" ... */ if (parser->cur >= parser->end || *parser->cur != ':')