mirror of
https://github.com/php/php-src.git
synced 2025-01-10 13:03:54 +08:00
- fix #49274, filter_var does not accept object without a toString implementation
This commit is contained in:
parent
7713cc89d9
commit
b1f10764f9
@ -379,6 +379,19 @@ static void php_zval_filter(zval **value, long filter, long flags, zval *options
|
||||
if (copy) {
|
||||
SEPARATE_ZVAL(value);
|
||||
}
|
||||
|
||||
/* #49274, fatal error with object without a toString method
|
||||
Fails nicely instead of getting a recovarable fatal error. */
|
||||
if (Z_TYPE_PP(value) == IS_OBJECT) {
|
||||
zend_class_entry *ce;
|
||||
|
||||
ce = Z_OBJCE_PP(value);
|
||||
if (!ce->__tostring) {
|
||||
ZVAL_FALSE(*value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Here be strings */
|
||||
convert_to_string(*value);
|
||||
|
||||
|
10
ext/filter/tests/bug49274.phpt
Normal file
10
ext/filter/tests/bug49274.phpt
Normal file
@ -0,0 +1,10 @@
|
||||
--TEST--
|
||||
#49274, fatal error when an object does not implement toString
|
||||
--SKIPIF--
|
||||
<?php if (!extension_loaded("filter")) die("skip"); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
var_dump(filter_var(new stdClass, FILTER_VALIDATE_EMAIL));
|
||||
?>
|
||||
--EXPECTF--
|
||||
bool(false)
|
Loading…
Reference in New Issue
Block a user