Skip to content

Commit 7eff405

Browse files
committed
Merge branch 'PHP-8.0'
* PHP-8.0: Alternative fix for bug 77423
2 parents b6bfb27 + effa287 commit 7eff405

File tree

8 files changed

+39
-29
lines changed

8 files changed

+39
-29
lines changed

ext/filter/logical_filters.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,22 @@ void php_filter_validate_domain(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
563563
}
564564
/* }}} */
565565

566+
static int is_userinfo_valid(zend_string *str)
567+
{
568+
const char *valid = "-._~!$&'()*+,;=:";
569+
const char *p = ZSTR_VAL(str);
570+
while (p - ZSTR_VAL(str) < ZSTR_LEN(str)) {
571+
if (isalpha(*p) || isdigit(*p) || strchr(valid, *p)) {
572+
p++;
573+
} else if (*p == '%' && p - ZSTR_VAL(str) <= ZSTR_LEN(str) - 3 && isdigit(*(p+1)) && isxdigit(*(p+2))) {
574+
p += 3;
575+
} else {
576+
return 0;
577+
}
578+
}
579+
return 1;
580+
}
581+
566582
void php_filter_validate_url(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
567583
{
568584
php_url *url;
@@ -618,6 +634,13 @@ void php_filter_validate_url(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
618634
php_url_free(url);
619635
RETURN_VALIDATION_FAILED
620636
}
637+
638+
if (url->user != NULL && !is_userinfo_valid(url->user)) {
639+
php_url_free(url);
640+
RETURN_VALIDATION_FAILED
641+
642+
}
643+
621644
php_url_free(url);
622645
}
623646
/* }}} */

ext/standard/tests/url/bug77423.phpt renamed to ext/filter/tests/bug77423.phpt

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,8 @@ $urls = array(
1010
);
1111
foreach ($urls as $url) {
1212
var_dump(filter_var($url, FILTER_VALIDATE_URL));
13-
var_dump(parse_url($url));
1413
}
1514
?>
1615
--EXPECT--
1716
bool(false)
18-
array(3) {
19-
["scheme"]=>
20-
string(4) "http"
21-
["host"]=>
22-
string(19) "php.net\@aliyun.com"
23-
["path"]=>
24-
string(7) "/aaa.do"
25-
}
2617
bool(false)
27-
array(2) {
28-
["scheme"]=>
29-
string(5) "https"
30-
["host"]=>
31-
string(26) "example.com\[email protected]"
32-
}

ext/standard/tests/strings/url_t.phpt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -589,13 +589,15 @@ $sample_urls = array (
589589
string(16) "some_page_ref123"
590590
}
591591

592-
--> http://secret@[email protected]:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123: array(6) {
592+
--> http://secret@[email protected]:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123: array(7) {
593593
["scheme"]=>
594594
string(4) "http"
595595
["host"]=>
596-
string(26) "secret@hideout@www.php.net"
596+
string(11) "www.php.net"
597597
["port"]=>
598598
int(80)
599+
["user"]=>
600+
string(14) "secret@hideout"
599601
["path"]=>
600602
string(10) "/index.php"
601603
["query"]=>

ext/standard/tests/url/parse_url_basic_001.phpt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,13 +514,15 @@ echo "Done";
514514
string(16) "some_page_ref123"
515515
}
516516

517-
--> http://secret@[email protected]:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123: array(6) {
517+
--> http://secret@[email protected]:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123: array(7) {
518518
["scheme"]=>
519519
string(4) "http"
520520
["host"]=>
521-
string(26) "secret@hideout@www.php.net"
521+
string(11) "www.php.net"
522522
["port"]=>
523523
int(80)
524+
["user"]=>
525+
string(14) "secret@hideout"
524526
["path"]=>
525527
string(10) "/index.php"
526528
["query"]=>

ext/standard/tests/url/parse_url_basic_003.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ echo "Done";
6262
--> http://secret:@www.php.net/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(11) "www.php.net"
6363
--> http://:[email protected]:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(11) "www.php.net"
6464
--> http://secret:[email protected]/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(11) "www.php.net"
65-
--> http://secret@[email protected]:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(26) "secret@hideout@www.php.net"
65+
--> http://secret@[email protected]:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(11) "www.php.net"
6666
--> http://secret:hid:[email protected]:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(11) "www.php.net"
6767
--> nntp://news.php.net : string(12) "news.php.net"
6868
--> ftp://ftp.gnu.org/gnu/glic/glibc.tar.gz : string(11) "ftp.gnu.org"

ext/standard/tests/url/parse_url_basic_005.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ echo "Done";
6262
--> http://secret:@www.php.net/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(6) "secret"
6363
--> http://:[email protected]:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(0) ""
6464
--> http://secret:[email protected]/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(6) "secret"
65-
--> http://secret@[email protected]:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : NULL
65+
--> http://secret@[email protected]:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(14) "secret@hideout"
6666
--> http://secret:hid:[email protected]:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(6) "secret"
6767
--> nntp://news.php.net : NULL
6868
--> ftp://ftp.gnu.org/gnu/glic/glibc.tar.gz : NULL

ext/standard/tests/url/parse_url_unterminated.phpt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,13 +522,15 @@ echo "Done";
522522
string(16) "some_page_ref123"
523523
}
524524

525-
--> http://secret@[email protected]:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123: array(6) {
525+
--> http://secret@[email protected]:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123: array(7) {
526526
["scheme"]=>
527527
string(4) "http"
528528
["host"]=>
529-
string(26) "secret@hideout@www.php.net"
529+
string(11) "www.php.net"
530530
["port"]=>
531531
int(80)
532+
["user"]=>
533+
string(14) "secret@hideout"
532534
["path"]=>
533535
string(10) "/index.php"
534536
["query"]=>

ext/standard/url.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -249,17 +249,13 @@ PHPAPI php_url *php_url_parse_ex2(char const *str, size_t length, bool *has_port
249249
ret->pass = zend_string_init(pp, (p-pp), 0);
250250
php_replace_controlchars_ex(ZSTR_VAL(ret->pass), ZSTR_LEN(ret->pass));
251251
} else {
252-
if (!is_userinfo_valid(s, p-s)) {
253-
goto check_port;
254-
}
255-
ret->user = zend_string_init(s, (p-s), 0);
256-
php_replace_controlchars_ex(ZSTR_VAL(ret->user), ZSTR_LEN(ret->user));
252+
ret->user = zend_string_init(s, (p-s), 0);
253+
php_replace_controlchars_ex(ZSTR_VAL(ret->user), ZSTR_LEN(ret->user));
257254
}
258255

259256
s = p + 1;
260257
}
261258

262-
check_port:
263259
/* check for port */
264260
if (s < ue && *s == '[' && *(e-1) == ']') {
265261
/* Short circuit portscan,

0 commit comments

Comments
 (0)