]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: uri-util - Add support for prefix parsing.
authorStephan Bosch <stephan.bosch@open-xchange.com>
Sat, 20 Nov 2021 14:53:36 +0000 (15:53 +0100)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Mon, 17 Jan 2022 11:52:10 +0000 (13:52 +0200)
src/lib/uri-util.c
src/lib/uri-util.h

index 5713a1438d8dffcd9863ade1111f0b8dc3b45f25..35b296cc99a51a5f54f17050907acab899867b2d 100644 (file)
@@ -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));
index cc8febac5ada2a88de7a13220b7f5297f36ce09f..a8753b8b10f8ba72c48b39907da6eaa22e691f0f 100644 (file)
@@ -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)