svn: /php/php-src/ branches/PHP_5_2/ext/filter/filter.c branches/PHP_5_2/ext/filter/tests/bug49274.phpt branches/PHP_5_3/ext/filter/filter.c
branches/PHP_5_3/ext/filter/tests/bug49274.phpt trunk/ext/filter/filter.c trunk/ext/filter/tests/bug49274.phpt
| From: | Pierre-Alain Joye | Date: | Sat, 05 Sep 2009 17:35:26 +0000 |
| Subject: | svn: /php/php-src/ branches/PHP_5_2/ext/filter/filter.c branches/PHP_5_2/ext/filter/tests/bug49274.phpt branches/PHP_5_3/ext/filter/filter.c branches/PHP_5_3/ext/filter/tests/bug49274.phpt trunk/ext/filter/filter.c trunk/ext/filter/tests/bug49274.phpt |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-60328@lists.php.net to get a copy of this message | ||
pajoye Sat, 05 Sep 2009 17:35:26 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=288083
Log:
- fix #49274, filter_var does not accept object without a toString implementation
Bug: http://bugs.php.net/49274 (Analyzed) filter_var()
should accept objects without fatal error
Changed paths:
U php/php-src/branches/PHP_5_2/ext/filter/filter.c
A php/php-src/branches/PHP_5_2/ext/filter/tests/bug49274.phpt
U php/php-src/branches/PHP_5_3/ext/filter/filter.c
A php/php-src/branches/PHP_5_3/ext/filter/tests/bug49274.phpt
U php/php-src/trunk/ext/filter/filter.c
A php/php-src/trunk/ext/filter/tests/bug49274.phpt
Modified: php/php-src/branches/PHP_5_2/ext/filter/filter.c
===================================================================
--- php/php-src/branches/PHP_5_2/ext/filter/filter.c 2009-09-05 17:11:44 UTC (rev 288082)
+++ php/php-src/branches/PHP_5_2/ext/filter/filter.c 2009-09-05 17:35:26 UTC (rev 288083)
@@ -316,6 +316,19 @@
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);
Added: php/php-src/branches/PHP_5_2/ext/filter/tests/bug49274.phpt
===================================================================
--- php/php-src/branches/PHP_5_2/ext/filter/tests/bug49274.phpt (rev 0)
+++ php/php-src/branches/PHP_5_2/ext/filter/tests/bug49274.phpt 2009-09-05 17:35:26 UTC (rev 288083)
@@ -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)
Modified: php/php-src/branches/PHP_5_3/ext/filter/filter.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/filter/filter.c 2009-09-05 17:11:44 UTC (rev 288082)
+++ php/php-src/branches/PHP_5_3/ext/filter/filter.c 2009-09-05 17:35:26 UTC (rev 288083)
@@ -365,6 +365,19 @@
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);
Added: php/php-src/branches/PHP_5_3/ext/filter/tests/bug49274.phpt
===================================================================
--- php/php-src/branches/PHP_5_3/ext/filter/tests/bug49274.phpt (rev 0)
+++ php/php-src/branches/PHP_5_3/ext/filter/tests/bug49274.phpt 2009-09-05 17:35:26 UTC (rev 288083)
@@ -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)
Modified: php/php-src/trunk/ext/filter/filter.c
===================================================================
--- php/php-src/trunk/ext/filter/filter.c 2009-09-05 17:11:44 UTC (rev 288082)
+++ php/php-src/trunk/ext/filter/filter.c 2009-09-05 17:35:26 UTC (rev 288083)
@@ -379,6 +379,19 @@
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);
Added: php/php-src/trunk/ext/filter/tests/bug49274.phpt
===================================================================
--- php/php-src/trunk/ext/filter/tests/bug49274.phpt (rev 0)
+++ php/php-src/trunk/ext/filter/tests/bug49274.phpt 2009-09-05 17:35:26 UTC (rev 288083)
@@ -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)