Mercurial > dovecot > core-2.2
changeset 20867:32678cf64cd1
uri-util: Added public function for parsing single percent encoding instances.
author | Stephan Bosch <stephan@rename-it.nl> |
---|---|
date | Sun, 08 May 2016 22:56:59 +0200 |
parents | 07f2f4327553 |
children | 82e8fc1b394f |
files | src/lib/uri-util.c src/lib/uri-util.h |
diffstat | 2 files changed, 25 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib/uri-util.c Sat Feb 20 19:47:58 2016 +0200 +++ b/src/lib/uri-util.c Sun May 08 22:56:59 2016 +0200 @@ -91,12 +91,17 @@ return -1; } -static int ATTR_NULL(3) -uri_parse_pct_encoded(struct uri_parser *parser, const unsigned char **p, - const unsigned char *pend, unsigned char *ch_r) +static int +uri_parse_pct_encoded_data(struct uri_parser *parser, + const unsigned char **p, const unsigned char *pend, + unsigned char *ch_r) ATTR_NULL(3) { int value; + if (**p != '%' || (pend != NULL && *p >= pend)) + return 0; + *p += 1; + if (**p == 0 || *(*p+1) == 0 || (pend != NULL && *p+1 >= pend)) { parser->error = "Unexpected URI boundary after '%'"; return -1; @@ -128,16 +133,20 @@ return 1; } +int uri_parse_pct_encoded(struct uri_parser *parser, + unsigned char *ch_r) +{ + return uri_parse_pct_encoded_data + (parser, &parser->cur, parser->end, ch_r); +} + static int uri_parse_unreserved_char(struct uri_parser *parser, unsigned char *ch_r) { - if (*parser->cur == '%') { - parser->cur++; - if (uri_parse_pct_encoded(parser, &parser->cur, - parser->end, ch_r) <= 0) - return -1; - return 1; - } + int ret; + + if ((ret=uri_parse_pct_encoded(parser, ch_r)) != 0) + return ret; if ((*parser->cur & 0x80) != 0) return 0; @@ -160,7 +169,6 @@ if ((ret = uri_parse_unreserved_char(parser, &ch)) < 0) return -1; - if (ret == 0) break; @@ -178,6 +186,7 @@ const unsigned char *p = (const unsigned char *)data; const unsigned char *pend = (const unsigned char *)until; string_t *decoded; + int ret; if (pend == NULL) { /* NULL means unlimited; solely rely on '\0' */ @@ -194,11 +203,10 @@ while (p < pend && *p != '\0') { unsigned char ch; - if (*p == '%') { - p++; - if (uri_parse_pct_encoded(parser, &p, NULL, &ch) <= 0) + if ((ret=uri_parse_pct_encoded_data + (parser, &p, NULL, &ch)) != 0) { + if (ret < 0) return FALSE; - str_append_c(decoded, ch); } else { str_append_c(decoded, *p);
--- a/src/lib/uri-util.h Sat Feb 20 19:47:58 2016 +0200 +++ b/src/lib/uri-util.h Sun May 08 22:56:59 2016 +0200 @@ -28,6 +28,8 @@ string_t *tmpbuf; }; +int uri_parse_pct_encoded(struct uri_parser *parser, + unsigned char *ch_r); int uri_parse_unreserved(struct uri_parser *parser, string_t *part); bool uri_data_decode(struct uri_parser *parser, const char *data,