Skip to content

Commit 6715860

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3: Fix GH-16523: FILTER_FLAG_HOSTNAME accepts ending hyphen
2 parents a026692 + 7930867 commit 6715860

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ PHP NEWS
5252
. Fixed bug GH-16397 (Segmentation fault when comparing FFI object).
5353
(nielsdos)
5454

55+
- Filter:
56+
. Fixed bug GH-16523 (FILTER_FLAG_HOSTNAME accepts ending hyphen). (cmb)
57+
5558
- GD:
5659
. Fixed bug GH-16334 (imageaffine overflow on matrix elements).
5760
(David Carlier)

ext/filter/logical_filters.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ static int _php_filter_validate_domain(char * domain, size_t len, zend_long flag
542542
/* Reset label length counter */
543543
i = 1;
544544
} else {
545-
if (i > 63 || (hostname && *s != '-' && !isalnum((int)*(unsigned char *)s))) {
545+
if (i > 63 || (hostname && (*s != '-' || *(s + 1) == '\0') && !isalnum((int)*(unsigned char *)s))) {
546546
return 0;
547547
}
548548

ext/filter/tests/gh16523.phpt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
GH-16523 (FILTER_FLAG_HOSTNAME accepts ending hyphen)
3+
--EXTENSIONS--
4+
filter
5+
--FILE--
6+
<?php
7+
$domains = [
8+
'a-.bc.com',
9+
'a.bc-.com',
10+
'a.bc.com-',
11+
];
12+
13+
foreach ($domains as $domain) {
14+
var_dump(filter_var($domain, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME));
15+
}
16+
?>
17+
--EXPECT--
18+
bool(false)
19+
bool(false)
20+
bool(false)

0 commit comments

Comments
 (0)