]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
uri-util: Allow empty host name in the generic URI syntax as specified in RFC 3986.
authorStephan Bosch <stephan@rename-it.nl>
Sat, 25 Apr 2015 09:42:06 +0000 (11:42 +0200)
committerStephan Bosch <stephan@rename-it.nl>
Sat, 25 Apr 2015 09:42:06 +0000 (11:42 +0200)
src/lib-http/http-url.c
src/lib-imap/imap-url.c
src/lib/uri-util.c

index b0884f53ee4df8b4095d310780c5882536aa1de9..8ac42635fdd9403da8d9cbab3e880f9f32c1fc03 100644 (file)
@@ -37,6 +37,16 @@ static bool http_url_parse_authority(struct http_url_parser *url_parser)
 
        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;
index f6e4983e6dfa20d0301d9025fd4ac5a214b61fa7..96c7b45d4b565c8c6c88895f1af51d6837574973 100644 (file)
@@ -193,7 +193,14 @@ static int imap_url_parse_iserver(struct imap_url_parser *url_parser)
        /* "//" 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;
index f386b9ad9ab3572cf34214e829724d57f929ed93..dd426f5efdc0b9caf5ee165386ac0b376989d2a3 100644 (file)
@@ -327,8 +327,6 @@ uri_parse_ipv4address(struct uri_parser *parser, string_t *literal,
 
 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 @@ static int uri_parse_reg_name(struct uri_parser *parser, string_t *reg_name)
                if (ret > 0) {
                        if (reg_name != NULL)
                                str_append_c(reg_name, c);
-                       len++;
                        continue;
                }
 
@@ -355,12 +352,11 @@ static int uri_parse_reg_name(struct uri_parser *parser, string_t *reg_name)
                        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 @@ static int uri_parse_host(struct uri_parser *parser, struct uri_authority *auth)
        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 @@ int uri_parse_authority(struct uri_parser *parser,
        }
 
        /* 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 != ':')