changeset 21364:518bc42408d6

lib, lib-http: add HTTP_URL_ALLOW_PCT_NUL flag This allows a URL to contain %00.
author Martti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
date Fri, 16 Dec 2016 20:27:09 +0200
parents cf8705ec586c
children cc6e4b239003
files src/lib-http/http-url.c src/lib-http/http-url.h src/lib/uri-util.c src/lib/uri-util.h
diffstat 4 files changed, 7 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-http/http-url.c	Tue Dec 27 14:01:14 2016 +0200
+++ b/src/lib-http/http-url.c	Fri Dec 16 20:27:09 2016 +0200
@@ -343,6 +343,7 @@
 
 	memset(&url_parser, '\0', sizeof(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;
--- a/src/lib-http/http-url.h	Tue Dec 27 14:01:14 2016 +0200
+++ b/src/lib-http/http-url.h	Fri Dec 16 20:27:09 2016 +0200
@@ -40,7 +40,9 @@
 	/* 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,
--- a/src/lib/uri-util.c	Tue Dec 27 14:01:14 2016 +0200
+++ b/src/lib/uri-util.c	Fri Dec 16 20:27:09 2016 +0200
@@ -125,7 +125,7 @@
 	*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;
--- a/src/lib/uri-util.h	Tue Dec 27 14:01:14 2016 +0200
+++ b/src/lib/uri-util.h	Fri Dec 16 20:27:09 2016 +0200
@@ -26,6 +26,8 @@
 	const unsigned char *begin, *cur, *end;
 
 	string_t *tmpbuf;
+
+	bool allow_pct_nul:1;
 };
 
 int uri_parse_pct_encoded(struct uri_parser *parser,