Skip to content

Commit 0a6f681

Browse files
cmb69patrickallaert
authored andcommitted
Fix #81708: UAF due to php_filter_float() failing for ints
We must only release the zval, if we actually assign a new zval.
1 parent 98b8b3e commit 0a6f681

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

ext/filter/logical_filters.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,10 +444,10 @@ void php_filter_float(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
444444

445445
switch (is_numeric_string(num, p - num, &lval, &dval, 0)) {
446446
case IS_LONG:
447-
zval_ptr_dtor(value);
448447
if ((min_range_set && (lval < min_range)) || (max_range_set && (lval > max_range))) {
449448
goto error;
450449
}
450+
zval_ptr_dtor(value);
451451
ZVAL_DOUBLE(value, (double)lval);
452452
break;
453453
case IS_DOUBLE:

ext/filter/tests/bug81708.phpt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
Bug #81708 (UAF due to php_filter_float() failing for ints)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded("filter")) die("skip filter extension not available");
6+
?>
7+
--INI--
8+
opcache.enable_cli=0
9+
--FILE--
10+
<?php
11+
$input = "+" . str_repeat("1", 2); // avoid string interning
12+
filter_var(
13+
$input,
14+
FILTER_VALIDATE_FLOAT,
15+
["options" => ['min_range' => -1, 'max_range' => 1]]
16+
);
17+
var_dump($input);
18+
?>
19+
--EXPECT--
20+
string(3) "+11"

0 commit comments

Comments
 (0)