fix #66 & fix #67
authorMichael Wallner <mike@php.net>
Tue, 4 Apr 2017 18:48:42 +0000 (20:48 +0200)
committerMichael Wallner <mike@php.net>
Mon, 3 Jul 2017 07:55:56 +0000 (09:55 +0200)
src/php_http_url.c
tests/gh-issue48.phpt

index ce09754a91874f44fe6e32f1306cdcaa131610c9..029e6a8ca37c3cf64a59c06ddb1e280fb7b63239 100644 (file)
@@ -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;
                                }
index 985f39d83dd7c2764604ac937550687efe32b9a5..61438f1039c9d4f53766d8d5b6aeccd976b80c42 100644 (file)
@@ -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=&#'