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;
/* "//" 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;
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 )
if (ret > 0) {
if (reg_name != NULL)
str_append_c(reg_name, c);
- len++;
continue;
}
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
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;
}
}
/* 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 != ':')