]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib, lib-http: add HTTP_URL_ALLOW_PCT_NUL flag
authorMartti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
Fri, 16 Dec 2016 18:27:09 +0000 (20:27 +0200)
committerMartti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
Tue, 3 Jan 2017 21:26:47 +0000 (23:26 +0200)
This allows a URL to contain %00.

src/lib-http/http-url.c
src/lib-http/http-url.h
src/lib/uri-util.c
src/lib/uri-util.h

index a2ae4a671fee561c90575f51e5102a9f4bc54047..2bd4c36e5a948d952dea3c854faa42fad36c19f7 100644 (file)
@@ -337,6 +337,7 @@ int http_url_parse(const char *url, struct http_url *base,
 
        i_zero(&url_parser);
        uri_parser_init(&url_parser.parser, pool, url);
+       url_parser.parser.allow_pct_nul = (flags & HTTP_URL_ALLOW_PCT_NUL) != 0;
 
        url_parser.url = p_new(pool, struct http_url, 1);
        url_parser.base = base;
index 4472fe3ae0fa217b375cf73c6b2e800a2d336539..cb0f0affe9d5a203166db57c4f807ea9fb5ebe3b 100644 (file)
@@ -38,7 +38,9 @@ enum http_url_parse_flags {
        /* Allow '#fragment' part in HTTP URL */
        HTTP_URL_ALLOW_FRAGMENT_PART = 0x02,
        /* Allow 'user:password@' part in HTTP URL */
-       HTTP_URL_ALLOW_USERINFO_PART = 0x04
+       HTTP_URL_ALLOW_USERINFO_PART = 0x04,
+       /* Allow URL to contain %00 */
+       HTTP_URL_ALLOW_PCT_NUL = 0x08,
 };
 
 int http_url_parse(const char *url, struct http_url *base,
index ea1f1279ecb46b11c595d56a5fbc73cdb706b1aa..5ddafd3df84db6b8877ece6d064d91604d2d54de 100644 (file)
@@ -164,7 +164,7 @@ uri_parse_pct_encoded_data(struct uri_parser *parser,
        *ch_r |= (value & 0x0f);
        *p += 1;
 
-       if (*ch_r == '\0') {
+       if (!parser->allow_pct_nul && *ch_r == '\0') {
                parser->error =
                        "Percent encoding is not allowed to encode NUL character";
                return -1;
index 73fd95bdcbc8706a3903034316ce43b5edd57466..1546fd5232f4fdce1fa088b0e7cc8415f215f738 100644 (file)
@@ -34,6 +34,8 @@ struct uri_parser {
        const unsigned char *begin, *cur, *end;
 
        string_t *tmpbuf;
+
+       bool allow_pct_nul:1;
 };
 
 /* parse one instance of percent encoding. Returns 1 for success,