dovecot-2.2: uri-util: Allow empty host name in the generic URI ...
dovecot at dovecot.org
dovecot at dovecot.org
Wed Apr 29 09:22:44 UTC 2015
details: http://hg.dovecot.org/dovecot-2.2/rev/9024d226b813
changeset: 18495:9024d226b813
user: Stephan Bosch <stephan at rename-it.nl>
date: Sat Apr 25 11:42:06 2015 +0200
description:
uri-util: Allow empty host name in the generic URI syntax as specified in RFC 3986.
diffstat:
src/lib-http/http-url.c | 10 ++++++++++
src/lib-imap/imap-url.c | 9 ++++++++-
src/lib/uri-util.c | 29 ++++++++---------------------
3 files changed, 26 insertions(+), 22 deletions(-)
diffs (110 lines):
diff -r 63224afb8c02 -r 9024d226b813 src/lib-http/http-url.c
--- 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;
diff -r 63224afb8c02 -r 9024d226b813 src/lib-imap/imap-url.c
--- 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;
diff -r 63224afb8c02 -r 9024d226b813 src/lib/uri-util.c
--- 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 != ':')
More information about the dovecot-cvs
mailing list