diff options
| author | Stanislav Malyshev <stas@php.net> | 2021-01-26 23:01:40 -0800 |
|---|---|---|
| committer | Stanislav Malyshev <stas@php.net> | 2021-01-26 23:01:40 -0800 |
| commit | 7eff4057dedeffee81b23f23d48c06a2082f9a06 (patch) | |
| tree | db72b0ddd54f019025ba4fc0d46a7ed316b52f2e /ext/filter | |
| parent | b6bfb27b8e1d2b57b650302e2aac956034b2111e (diff) | |
| parent | effa287b35775de9a600dddfd01cad081fa5f28f (diff) | |
| download | php-git-7eff4057dedeffee81b23f23d48c06a2082f9a06.tar.gz | |
Merge branch 'PHP-8.0'
* PHP-8.0:
Alternative fix for bug 77423
Diffstat (limited to 'ext/filter')
| -rw-r--r-- | ext/filter/logical_filters.c | 23 | ||||
| -rw-r--r-- | ext/filter/tests/bug77423.phpt | 17 |
2 files changed, 40 insertions, 0 deletions
diff --git a/ext/filter/logical_filters.c b/ext/filter/logical_filters.c index 1e4925b421..a27e0369a2 100644 --- a/ext/filter/logical_filters.c +++ b/ext/filter/logical_filters.c @@ -563,6 +563,22 @@ void php_filter_validate_domain(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */ } /* }}} */ +static int is_userinfo_valid(zend_string *str) +{ + const char *valid = "-._~!$&'()*+,;=:"; + const char *p = ZSTR_VAL(str); + while (p - ZSTR_VAL(str) < ZSTR_LEN(str)) { + if (isalpha(*p) || isdigit(*p) || strchr(valid, *p)) { + p++; + } else if (*p == '%' && p - ZSTR_VAL(str) <= ZSTR_LEN(str) - 3 && isdigit(*(p+1)) && isxdigit(*(p+2))) { + p += 3; + } else { + return 0; + } + } + return 1; +} + void php_filter_validate_url(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */ { php_url *url; @@ -618,6 +634,13 @@ bad_url: php_url_free(url); RETURN_VALIDATION_FAILED } + + if (url->user != NULL && !is_userinfo_valid(url->user)) { + php_url_free(url); + RETURN_VALIDATION_FAILED + + } + php_url_free(url); } /* }}} */ diff --git a/ext/filter/tests/bug77423.phpt b/ext/filter/tests/bug77423.phpt new file mode 100644 index 0000000000..bf63b7595c --- /dev/null +++ b/ext/filter/tests/bug77423.phpt @@ -0,0 +1,17 @@ +--TEST-- +Bug #77423 (parse_url() will deliver a wrong host to user) +--SKIPIF-- +<?php if (!function_exists('filter_var')) { echo "skip requires filter\n"; } ?> +--FILE-- +<?php +$urls = array( + "http://php.net\@aliyun.com/aaa.do", + "https://example.com\uFF03@bing.com", +); +foreach ($urls as $url) { + var_dump(filter_var($url, FILTER_VALIDATE_URL)); +} +?> +--EXPECT-- +bool(false) +bool(false) |
