summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph M. Becker <cmbecker69@gmx.de>2016-09-09 14:30:24 +0200
committerChristoph M. Becker <cmbecker69@gmx.de>2016-09-09 14:30:24 +0200
commit23e721fc9303dd7423f989f6ff360cdff74aeca1 (patch)
tree41f7680eb6f22f90bd47c747722ed4ec57977515
parentcb91a51b0052d512c0110ec934a23e263258e461 (diff)
downloadphp-git-23e721fc9303dd7423f989f6ff360cdff74aeca1.tar.gz
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.
-rw-r--r--NEWS2
-rw-r--r--ext/filter/filter.c5
-rw-r--r--ext/filter/tests/bug73054.phpt23
3 files changed, 28 insertions, 2 deletions
diff --git a/NEWS b/NEWS
index 420bf36107..831293f7cc 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 479a63a6e0..5b79667bd9 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 0000000000..77a1a88b33
--- /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===