Skip to content

Commit

Permalink
lib, lib-http: add HTTP_URL_ALLOW_PCT_NUL flag
Browse files Browse the repository at this point in the history
This allows a URL to contain %00.
  • Loading branch information
mrannanj committed Jan 3, 2017
1 parent 58fed57 commit 89e0400
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/lib-http/http-url.c
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion src/lib-http/http-url.h
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/uri-util.c
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/lib/uri-util.h
Expand Up @@ -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,
Expand Down

0 comments on commit 89e0400

Please sign in to comment.