Skip to content

Commit 764b7bf

Browse files
committed
Fix bug #80584: 0x and 0X are considered valid hex numbers by filter_var()
Closes GH-6573
1 parent 9f96b2b commit 764b7bf

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ PHP NEWS
1414
. Fixed bug #80537 (Wrong parameter type in DOMElement::removeAttributeNode
1515
stub). (Nikita)
1616

17+
- Filter:
18+
. Fixed bug #80584 (0x and 0X are considered valid hex numbers by
19+
filter_var()). (girgias)
20+
1721
- MySQLi:
1822
. Fixed bug #67983 (mysqlnd with MYSQLI_OPT_INT_AND_FLOAT_NATIVE fails to
1923
interpret bit columns). (Nikita)

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)