Skip to content

Commit

Permalink
Fix #81708: UAF due to php_filter_float() failing for ints
Browse files Browse the repository at this point in the history
We must only release the zval, if we actually assign a new zval.
  • Loading branch information
cmb69 authored and patrickallaert committed Feb 15, 2022
1 parent 98b8b3e commit 0a6f681
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ext/filter/logical_filters.c
Expand Up @@ -444,10 +444,10 @@ void php_filter_float(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */

switch (is_numeric_string(num, p - num, &lval, &dval, 0)) {
case IS_LONG:
zval_ptr_dtor(value);
if ((min_range_set && (lval < min_range)) || (max_range_set && (lval > max_range))) {
goto error;
}
zval_ptr_dtor(value);
ZVAL_DOUBLE(value, (double)lval);
break;
case IS_DOUBLE:
Expand Down
20 changes: 20 additions & 0 deletions ext/filter/tests/bug81708.phpt
@@ -0,0 +1,20 @@
--TEST--
Bug #81708 (UAF due to php_filter_float() failing for ints)
--SKIPIF--
<?php
if (!extension_loaded("filter")) die("skip filter extension not available");
?>
--INI--
opcache.enable_cli=0
--FILE--
<?php
$input = "+" . str_repeat("1", 2); // avoid string interning
filter_var(
$input,
FILTER_VALIDATE_FLOAT,
["options" => ['min_range' => -1, 'max_range' => 1]]
);
var_dump($input);
?>
--EXPECT--
string(3) "+11"

0 comments on commit 0a6f681

Please sign in to comment.