]> granicus.if.org Git - php/commitdiff
- fix #49274, filter_var does not accept object without a toString implementation
authorPierre Joye <pajoye@php.net>
Sat, 5 Sep 2009 17:35:26 +0000 (17:35 +0000)
committerPierre Joye <pajoye@php.net>
Sat, 5 Sep 2009 17:35:26 +0000 (17:35 +0000)
ext/filter/filter.c
ext/filter/tests/bug49274.phpt [new file with mode: 0644]

index e0c99a284cf50d369c2872594f75592e0227e94f..afa9623b90815b64368fcc54a8f42667ebfabf37 100644 (file)
@@ -316,6 +316,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);
 
diff --git a/ext/filter/tests/bug49274.phpt b/ext/filter/tests/bug49274.phpt
new file mode 100644 (file)
index 0000000..c87e6be
--- /dev/null
@@ -0,0 +1,10 @@
+--TEST--\r
+#49274, fatal error when an object does not implement toString\r
+--SKIPIF--\r
+<?php if (!extension_loaded("filter")) die("skip"); ?>\r
+--FILE--\r
+<?php\r
+var_dump(filter_var(new stdClass, FILTER_VALIDATE_EMAIL));\r
+?>\r
+--EXPECTF--    \r
+bool(false)\r