From: Stephan Bosch Date: Sat, 20 Nov 2021 14:53:36 +0000 (+0100) Subject: lib: uri-util - Add support for prefix parsing. X-Git-Tag: 2.4.0~4694 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=630094adabca5ff773ff7bb2d3e53a22e58461ee;p=thirdparty%2Fdovecot%2Fcore.git lib: uri-util - Add support for prefix parsing. --- diff --git a/src/lib/uri-util.c b/src/lib/uri-util.c index 5713a1438d..35b296cc99 100644 --- a/src/lib/uri-util.c +++ b/src/lib/uri-util.c @@ -795,6 +795,8 @@ uri_do_parse_authority(struct uri_parser *parser, struct uri_authority *auth, case ':': case '/': case '?': case '#': break; default: + if (parser->parse_prefix) + break; parser->error = "Invalid host identifier"; return -1; } @@ -812,6 +814,8 @@ uri_do_parse_authority(struct uri_parser *parser, struct uri_authority *auth, case '/': case '?': case '#': break; default: + if (parser->parse_prefix) + break; parser->error = "Invalid host port"; return -1; } @@ -880,8 +884,8 @@ int uri_parse_path_segment(struct uri_parser *parser, const char **segment_r) parser->cur++; } - if (parser->cur < parser->end && *parser->cur != '/' && - *parser->cur != '?' && *parser->cur != '#') { + if (!parser->parse_prefix && parser->cur < parser->end && + *parser->cur != '/' && *parser->cur != '?' && *parser->cur != '#') { parser->error = p_strdup_printf(parser->pool, "Path component contains invalid character %s", uri_char_sanitize(*parser->cur)); @@ -989,7 +993,7 @@ int uri_parse_path(struct uri_parser *parser, array_append_zero(&segments); *path_r = array_get(&segments, &count); } - if (parser->cur < parser->end && + if (!parser->parse_prefix && parser->cur < parser->end && *parser->cur != '?' && *parser->cur != '#') { parser->error = p_strdup_printf(parser->pool, "Path component contains invalid character %s", @@ -1031,7 +1035,8 @@ int uri_parse_query(struct uri_parser *parser, const char **query_r) parser->cur++; } - if (parser->cur < parser->end && *parser->cur != '#') { + if (!parser->parse_prefix && parser->cur < parser->end && + *parser->cur != '#') { parser->error = p_strdup_printf(parser->pool, "Query component contains invalid character %s", uri_char_sanitize(*parser->cur)); @@ -1076,7 +1081,7 @@ int uri_parse_fragment(struct uri_parser *parser, const char **fragment_r) parser->cur++; } - if (parser->cur < parser->end) { + if (!parser->parse_prefix && parser->cur < parser->end) { parser->error = p_strdup_printf(parser->pool, "Fragment component contains invalid character %s", uri_char_sanitize(*parser->cur)); diff --git a/src/lib/uri-util.h b/src/lib/uri-util.h index cc8febac5a..a8753b8b10 100644 --- a/src/lib/uri-util.h +++ b/src/lib/uri-util.h @@ -36,6 +36,7 @@ struct uri_parser { string_t *tmpbuf; bool allow_pct_nul:1; + bool parse_prefix:1; }; static inline const char *uri_char_sanitize(unsigned char c)