From 89e040049336e69c43fec09dcbdfd0f2ae5efd51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martti=20Rannanj=C3=A4rvi?= Date: Fri, 16 Dec 2016 20:27:09 +0200 Subject: [PATCH] lib, lib-http: add HTTP_URL_ALLOW_PCT_NUL flag This allows a URL to contain %00. --- src/lib-http/http-url.c | 1 + src/lib-http/http-url.h | 4 +++- src/lib/uri-util.c | 2 +- src/lib/uri-util.h | 2 ++ 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/lib-http/http-url.c b/src/lib-http/http-url.c index a2ae4a671f..2bd4c36e5a 100644 --- a/src/lib-http/http-url.c +++ b/src/lib-http/http-url.c @@ -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; diff --git a/src/lib-http/http-url.h b/src/lib-http/http-url.h index 4472fe3ae0..cb0f0affe9 100644 --- a/src/lib-http/http-url.h +++ b/src/lib-http/http-url.h @@ -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, diff --git a/src/lib/uri-util.c b/src/lib/uri-util.c index ea1f1279ec..5ddafd3df8 100644 --- a/src/lib/uri-util.c +++ b/src/lib/uri-util.c @@ -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; diff --git a/src/lib/uri-util.h b/src/lib/uri-util.h index 73fd95bdcb..1546fd5232 100644 --- a/src/lib/uri-util.h +++ b/src/lib/uri-util.h @@ -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,