From ea491dba64d6c15a515e0f1cc58d881c2e2dc2f3 Mon Sep 17 00:00:00 2001 From: Ilia Alshanetsky Date: Wed, 20 Dec 2006 19:20:01 +0000 Subject: [PATCH] Fixed bug #39898 (FILTER_VALIDATE_URL validates \r\n\t etc). --- NEWS | 1 + ext/filter/logical_filters.c | 15 +++++++++++---- ext/filter/tests/015.phpt | 28 ++++++++++++++++++---------- ext/filter/tests/033.phpt | 2 +- 4 files changed, 31 insertions(+), 15 deletions(-) diff --git a/NEWS b/NEWS index ff7b6a7ace..df6f5309fd 100644 --- a/NEWS +++ b/NEWS @@ -16,6 +16,7 @@ PHP NEWS - Fixed bug #39903 (Notice message when executing __halt_compiler() more than once). (Tony) +- Fixed bug #39898 (FILTER_VALIDATE_URL validates \r\n\t etc). (Ilia) - Fixed bug #39869 (safe_read does not initialize errno). (michiel at boland dot org, Dmitry) - Fixed bug #39850 (SplFileObject throws contradictory/wrong error messages diff --git a/ext/filter/logical_filters.c b/ext/filter/logical_filters.c index e231a3ed43..37ff815b95 100644 --- a/ext/filter/logical_filters.c +++ b/ext/filter/logical_filters.c @@ -477,6 +477,13 @@ void php_filter_validate_regexp(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */ void php_filter_validate_url(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */ { php_url *url; + int old_len = Z_STRLEN_P(value); + + php_filter_url(value, flags, option_array, charset TSRMLS_DC); + + if (Z_TYPE_P(value) != IS_STRING || old_len != Z_STRLEN_P(value)) { + RETURN_VALIDATION_FAILED + } /* Use parse_url - if it returns false, we return NULL */ url = php_url_parse_ex(Z_STRVAL_P(value), Z_STRLEN_P(value)); @@ -486,10 +493,10 @@ void php_filter_validate_url(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */ } if ( - ((flags & FILTER_FLAG_SCHEME_REQUIRED) && url->scheme == NULL) || - ((flags & FILTER_FLAG_HOST_REQUIRED) && url->host == NULL) || - ((flags & FILTER_FLAG_PATH_REQUIRED) && url->path == NULL) || - ((flags & FILTER_FLAG_QUERY_REQUIRED) && url->query == NULL) + url->scheme == NULL || + /* some schemas allow the host to be empty */ + (url->host == NULL && (strcmp(url->scheme, "mailto") && strcmp(url->scheme, "news") && strcmp(url->scheme, "file"))) || + ((flags & FILTER_FLAG_PATH_REQUIRED) && url->path == NULL) || ((flags & FILTER_FLAG_QUERY_REQUIRED) && url->query == NULL) ) { php_url_free(url); RETURN_VALIDATION_FAILED diff --git a/ext/filter/tests/015.phpt b/ext/filter/tests/015.phpt index 7024df4e24..a9c4a8cf48 100644 --- a/ext/filter/tests/015.phpt +++ b/ext/filter/tests/015.phpt @@ -24,6 +24,10 @@ $values = Array( '', -1, array(), +'mailto:foo@bar.com', +'news:news.php.net', +'file://foo/bar', +"http://\r\n/bar", ); foreach ($values as $value) { var_dump(filter_var($value, FILTER_VALIDATE_URL)); @@ -48,18 +52,22 @@ string(32) "http://www.example.com/index.php" string(31) "http://www.example/img/test.png" string(27) "http://www.example/img/dir/" string(26) "http://www.example/img/dir" -string(28) "http//www.example/wrong/url/" -string(17) "http:/www.example" +bool(false) +bool(false) string(18) "file:///tmp/test.c" string(26) "ftp://ftp.example.com/tmp/" -string(11) "/tmp/test.c" -string(1) "/" bool(false) -string(6) "http:/" -string(5) "http:" -string(4) "http" -string(0) "" -string(2) "-1" +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +string(18) "mailto:foo@bar.com" +string(17) "news:news.php.net" +string(14) "file://foo/bar" bool(false) bool(false) string(10) "http://qwe" @@ -70,4 +78,4 @@ bool(false) string(42) "http://www.example.com/path/at/the/server/" bool(false) string(40) "http://www.example.com/index.php?a=b&c=d" -Done +Done \ No newline at end of file diff --git a/ext/filter/tests/033.phpt b/ext/filter/tests/033.phpt index fc0bd2687d..18a3616903 100644 --- a/ext/filter/tests/033.phpt +++ b/ext/filter/tests/033.phpt @@ -11,7 +11,7 @@ int 1 123 boolean 1 float 1 123 validate_regexp O'Henry -validate_url PHP 1 foo@bar.com http://a.b.c 1.2.3.4 123 123abc<>() O'Henry 하퍼 +validate_url http://a.b.c validate_email foo@bar.com validate_ip 1.2.3.4 string PHP 1 foo@bar.com http://a.b.c 1.2.3.4 123 123abc() O'Henry 하퍼 -- 2.40.0