Fix #73054: default option ignored when object passed to int filter

If an object that can't be converted to string is validated, we must not
bail out early, but rather check for a requested default value.
This commit is contained in:
Christoph M. Becker 2016-09-09 14:30:24 +02:00
parent cb91a51b00
commit 23e721fc93
3 changed files with 28 additions and 2 deletions

2
NEWS
View File

@ -11,6 +11,8 @@ PHP NEWS
FILTER_FLAG_NO_PRIV_RANGE). (julien)
. Fixed bug #67167 (Wrong return value from FILTER_VALIDATE_BOOLEAN,
FILTER_NULL_ON_FAILURE). (levim, cmb)
. Fixed bug #73054 (default option ignored when object passed to int filter).
(cmb)
- GD:
. Fixed bug #67325 (imagetruecolortopalette: white is duplicated in palette).

View File

@ -380,14 +380,14 @@ static void php_zval_filter(zval **value, long filter, long flags, zval *options
ce = Z_OBJCE_PP(value);
if (!ce->__tostring) {
zval_ptr_dtor(value);
zval_dtor(*value);
/* #67167: doesn't return null on failure for objects */
if (flags & FILTER_NULL_ON_FAILURE) {
ZVAL_NULL(*value);
} else {
ZVAL_FALSE(*value);
}
return;
goto handle_default;
}
}
@ -396,6 +396,7 @@ static void php_zval_filter(zval **value, long filter, long flags, zval *options
filter_func.function(*value, flags, options, charset TSRMLS_CC);
handle_default:
if (
options && (Z_TYPE_P(options) == IS_ARRAY || Z_TYPE_P(options) == IS_OBJECT) &&
((flags & FILTER_NULL_ON_FAILURE && Z_TYPE_PP(value) == IS_NULL) ||

View File

@ -0,0 +1,23 @@
--TEST--
Bug #73054 (default option ignored when object passed to int filter)
--SKIPIF--
<?php
if (!extension_loaded('filter')) die('skip filter extension not available');
?>
--FILE--
<?php
var_dump(
filter_var(new stdClass, FILTER_VALIDATE_INT, [
'options' => ['default' => 2],
]),
filter_var(new stdClass, FILTER_VALIDATE_INT, [
'options' => ['default' => 2],
'flags' => FILTER_NULL_ON_FAILURE
])
);
?>
===DONE===
--EXPECT--
int(2)
int(2)
===DONE===