Skip to content

Commit af1b89f

Browse files
committed
Merge branch 'PHP-8.0'
* PHP-8.0: Fix bug #80584: 0x and 0X are considered valid hex numbers by filter_var()
2 parents a841390 + 764b7bf commit af1b89f

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

ext/filter/logical_filters.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,9 @@ void php_filter_int(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
233233
p++; len--;
234234
if (allow_hex && (*p == 'x' || *p == 'X')) {
235235
p++; len--;
236+
if (len == 0) {
237+
RETURN_VALIDATION_FAILED
238+
}
236239
if (php_filter_parse_hex(p, len, &ctx_value) < 0) {
237240
error = 1;
238241
}

ext/filter/tests/bug80584.phpt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
Bug #80584: "0x" and "0X" are considered valid hex numbers by filter_var()
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('filter')) die('skip filter extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
var_dump(filter_var('0x', FILTER_VALIDATE_INT, FILTER_FLAG_ALLOW_HEX));
10+
var_dump(filter_var('0X', FILTER_VALIDATE_INT, FILTER_FLAG_ALLOW_HEX));
11+
var_dump(filter_var('', FILTER_VALIDATE_INT, FILTER_FLAG_ALLOW_HEX));
12+
var_dump(filter_var('0', FILTER_VALIDATE_INT, FILTER_FLAG_ALLOW_HEX));
13+
?>
14+
--EXPECT--
15+
bool(false)
16+
bool(false)
17+
bool(false)
18+
int(0)

0 commit comments

Comments
 (0)