From: Michael Wallner Date: Tue, 4 Apr 2017 18:48:42 +0000 (+0200) Subject: fix #66 & fix #67 X-Git-Tag: RELEASE_3_2_0_RC1~50 X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=commitdiff_plain;h=fdf49093c6ef7cffdd82b44230ac4c75643223a3;ds=sidebyside fix #66 & fix #67 --- diff --git a/src/php_http_url.c b/src/php_http_url.c index ce09754..029e6a8 100644 --- a/src/php_http_url.c +++ b/src/php_http_url.c @@ -723,7 +723,7 @@ static const char * const parse_what[] = { static const char parse_xdigits[] = "0123456789ABCDEF"; -static size_t parse_mb(struct parse_state *state, parse_mb_what_t what, const char *ptr, const char *end, const char *begin, zend_bool silent) +static size_t parse_mb(struct parse_state *state, parse_mb_what_t what, const char *ptr, const char *end, const char *begin, zend_bool force_silent) { unsigned wchar; size_t consumed = 0; @@ -767,7 +767,7 @@ static size_t parse_mb(struct parse_state *state, parse_mb_what_t what, const ch return consumed; } - if (!silent) { + if (!force_silent && !(state->flags & PHP_HTTP_URL_SILENT_ERRORS)) { if (consumed) { php_error_docref(NULL, E_WARNING, "Failed to parse %s; unexpected multibyte sequence 0x%x at pos %u in '%s'", @@ -779,6 +779,11 @@ static size_t parse_mb(struct parse_state *state, parse_mb_what_t what, const ch } } + if (state->flags & PHP_HTTP_URL_IGNORE_ERRORS) { + state->buffer[state->offset++] = *ptr; + return 1; + } + return 0; } @@ -828,7 +833,7 @@ static ZEND_RESULT_CODE parse_userinfo(struct parse_state *state, const char *pt break; default: - if ((mb = parse_mb(state, PARSE_USERINFO, ptr, end, tmp, state->flags & PHP_HTTP_URL_SILENT_ERRORS))) { + if ((mb = parse_mb(state, PARSE_USERINFO, ptr, end, tmp, 0))) { ptr += mb - 1; break; } @@ -1411,7 +1416,7 @@ static ZEND_RESULT_CODE parse_hostinfo(struct parse_state *state, const char *pt return FAILURE; } break; - } else if (!(mb = parse_mb(state, PARSE_HOSTINFO, ptr, end, tmp, state->flags & PHP_HTTP_URL_SILENT_ERRORS))) { + } else if (!(mb = parse_mb(state, PARSE_HOSTINFO, ptr, end, tmp, 0))) { if (!(state->flags & PHP_HTTP_URL_IGNORE_ERRORS)) { return FAILURE; } @@ -1533,7 +1538,7 @@ static const char *parse_path(struct parse_state *state) break; default: - if (!(mb = parse_mb(state, PARSE_PATH, state->ptr, state->end, tmp, state->flags & PHP_HTTP_URL_SILENT_ERRORS))) { + if (!(mb = parse_mb(state, PARSE_PATH, state->ptr, state->end, tmp, 0))) { if (!(state->flags & PHP_HTTP_URL_IGNORE_ERRORS)) { return NULL; } @@ -1623,7 +1628,7 @@ static const char *parse_query(struct parse_state *state) break; default: - if (!(mb = parse_mb(state, PARSE_QUERY, state->ptr, state->end, tmp, state->flags & PHP_HTTP_URL_SILENT_ERRORS))) { + if (!(mb = parse_mb(state, PARSE_QUERY, state->ptr, state->end, tmp, 0))) { if (!(state->flags & PHP_HTTP_URL_IGNORE_ERRORS)) { return NULL; } @@ -1720,7 +1725,7 @@ static const char *parse_fragment(struct parse_state *state) break; default: - if (!(mb = parse_mb(state, PARSE_FRAGMENT, state->ptr, state->end, tmp, state->flags & PHP_HTTP_URL_SILENT_ERRORS))) { + if (!(mb = parse_mb(state, PARSE_FRAGMENT, state->ptr, state->end, tmp, 0))) { if (!(state->flags & PHP_HTTP_URL_IGNORE_ERRORS)) { return NULL; } diff --git a/tests/gh-issue48.phpt b/tests/gh-issue48.phpt index 985f39d..61438f1 100644 --- a/tests/gh-issue48.phpt +++ b/tests/gh-issue48.phpt @@ -141,11 +141,11 @@ http\Url::__construct(): Failed to parse hostinfo; unexpected byte 0xc3 at pos 1 Warning: http\Url::__construct(): Failed to parse hostinfo; unexpected byte 0xc3 at pos 1 in 'a%c%cb' in %sgh-issue48.php on line %d Warning: http\Url::__construct(): Failed to parse hostinfo; unexpected byte 0xc3 at pos 2 in 'a%c%cb' in %sgh-issue48.php on line %d -http://ab/ +http://a%r\xc3\xc3%rb/ # SILENT # IGNORE|SILENT -http://ab/ +http://a%r\xc3\xc3%rb/ ========== # DEFAULT http\Url::__construct(): Failed to parse hostinfo; unexpected '[' at pos 0 in '[foobar]:123' @@ -156,11 +156,11 @@ Warning: http\Url::__construct(): Failed to parse hostinfo; unexpected '[' at po Warning: http\Url::__construct(): Failed to parse hostinfo; unexpected byte 0x5b at pos 0 in '[foobar]:123' in %sgh-issue48.php on line %d Warning: http\Url::__construct(): Failed to parse hostinfo; unexpected byte 0x5d at pos 7 in '[foobar]:123' in %sgh-issue48.php on line %d -http://foobar:123/ +http://[foobar]:123/ # SILENT # IGNORE|SILENT -http://foobar:123/ +http://[foobar]:123/ ========== # DEFAULT http\Url::__construct(): Failed to parse fragment; invalid fragment identifier at pos 7 in '/?foo=&#'