com php-src: Fix #73054: default option ignored when object passed to int filter: NEWS ext/filter/filter.c ext/filter/tests/bug73054.phpt

From: Date: Fri, 09 Sep 2016 12:30:24 +0000
Subject: com php-src: Fix #73054: default option ignored when object passed to int filter: NEWS ext/filter/filter.c ext/filter/tests/bug73054.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-94394@lists.php.net to get a copy of this message
Commit: 23e721fc9303dd7423f989f6ff360cdff74aeca1 Author: Christoph M. Becker <cmbecker69@gmx.de> Fri, 9 Sep 2016 14:30:24 +0200 Parents: cb91a51b0052d512c0110ec934a23e263258e461 Branches: PHP-5.6 PHP-7.0 PHP-7.1 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=23e721fc9303dd7423f989f6ff360cdff74aeca1 Log: 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. Bugs: https://bugs.php.net/73054 Changed paths: M NEWS M ext/filter/filter..c A ext/filter/tests/bug73054.phpt Diff: diff --git a/NEWS b/NEWS index 420bf36..831293f 100644 --- a/NEWS +++ b/NEWS @@ -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). diff --git a/ext/filter/filter.c b/ext/filter/filter.c index 479a63a..5b79667 100644 --- a/ext/filter/filter.c +++ b/ext/filter/filter.c @@ -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) || diff --git a/ext/filter/tests/bug73054.phpt b/ext/filter/tests/bug73054.phpt new file mode 100644 index 0000000..77a1a88 --- /dev/null +++ b/ext/filter/tests/bug73054.phpt @@ -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===

« previous php.cvs (#94394) next »