]> granicus.if.org Git - php/commitdiff
Better fix for exception traces truncation with anon classes
authorBob Weinand <bobwei9@hotmail.com>
Tue, 18 Aug 2015 10:48:06 +0000 (12:48 +0200)
committerBob Weinand <bobwei9@hotmail.com>
Tue, 18 Aug 2015 10:48:06 +0000 (12:48 +0200)
NEWS
Zend/tests/bug69761.phpt
Zend/tests/exception_023.phpt [new file with mode: 0644]
Zend/zend_exceptions.c

diff --git a/NEWS b/NEWS
index 6a921d358bb6a07d550cb98cd03833e564d5ba3d..ea83714e2fed7cb1eb7eb963aa799d6f819a91b8 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -20,6 +20,7 @@ PHP                                                                        NEWS
   . Fixed bug #70241 (Skipped assertions affect Generator returns). (Bob)
   . Fixed bug #70239 (Creating a huge array doesn't result in exhausted,
     but segfault). (Laruence, Anatol)
+  . Fixed bug causing exception traces with anon classes to be truncated. (Bob)
 
 - CLI server:
   . Fixed bug #66606 (Sets HTTP_CONTENT_TYPE but not CONTENT_TYPE).
index 4b7e2787d81df5400e239d92062e3e6329a81c9f..2ec7cc10e1b9d7e9334ca992d04ba7ed5f76fb6a 100644 (file)
@@ -11,5 +11,6 @@ var_dump(serialize($instance));
 --EXPECTF--
 Fatal error: Uncaught Exception: Serialization of 'class@%s' is not allowed in %sbug69761.php:%d
 Stack trace:
-#0 %sbug69761.php(%d): serialize(Object(class@%s
+#0 %sbug69761.php(%d): serialize(Object(class@anonymous))
+#1 {main}
   thrown in %sbug69761.php on line %d
diff --git a/Zend/tests/exception_023.phpt b/Zend/tests/exception_023.phpt
new file mode 100644 (file)
index 0000000..34de77a
--- /dev/null
@@ -0,0 +1,16 @@
+--TEST--
+Ensure proper backtraces with anon classes
+--FILE--
+<?php
+
+(function($obj) {
+       throw new Exception();
+})(new class {});
+
+?>
+--EXPECTF--
+Fatal error: Uncaught Exception in %s:%d
+Stack trace:
+#0 %s(%d): {closure}(Object(class@anonymous))
+#1 {main}
+  thrown in %s on line %d
index 307589b5fef06ee1acfa7eb85c8be147ea253583..3af0b5ac075f83b6f66b9deab24984830408259f 100644 (file)
@@ -29,6 +29,7 @@
 #include "zend_vm.h"
 #include "zend_dtrace.h"
 #include "zend_smart_str.h"
+#include "php_globals.h"
 
 ZEND_API zend_class_entry *zend_ce_throwable;
 ZEND_API zend_class_entry *zend_ce_exception;
@@ -442,7 +443,7 @@ ZEND_METHOD(error_exception, getSeverity)
                                zend_error(E_WARNING, "Value for %s is no string", key);    \
                                smart_str_appends(str, "[unknown]");                        \
                        } else {                                                        \
-                               smart_str_append(str, Z_STR_P(tmp));   \
+                               smart_str_appends(str, Z_STRVAL_P(tmp));   \
                        }                                                               \
                } \
        } while (0)
@@ -556,7 +557,7 @@ static void _build_trace_args(zval *arg, smart_str *str) /* {{{ */
                        break;
                case IS_OBJECT:
                        smart_str_appends(str, "Object(");
-                       smart_str_append(str, Z_OBJCE_P(arg)->name);
+                       smart_str_appends(str, ZSTR_VAL(Z_OBJCE_P(arg)->name));
                        smart_str_appends(str, "), ");
                        break;
        }
@@ -1007,7 +1008,7 @@ ZEND_API void zend_exception_error(zend_object *ex, int severity) /* {{{ */
                        if (Z_TYPE(tmp) != IS_STRING) {
                                zend_error(E_WARNING, "%s::__toString() must return a string", ZSTR_VAL(ce_exception->name));
                        } else {
-                               zend_update_property_string(i_get_exception_base(&exception), &exception, "string", sizeof("string")-1, EG(exception) ? ZSTR_VAL(ce_exception->name) : Z_STRVAL(tmp));
+                               zend_update_property(i_get_exception_base(&exception), &exception, "string", sizeof("string")-1, &tmp);
                        }
                }
                zval_ptr_dtor(&tmp);
@@ -1036,7 +1037,7 @@ ZEND_API void zend_exception_error(zend_object *ex, int severity) /* {{{ */
                line = zval_get_long(GET_PROPERTY_SILENT(&exception, "line"));
 
                zend_error_va(severity, (file && ZSTR_LEN(file) > 0) ? ZSTR_VAL(file) : NULL, line,
-                       "Uncaught %s\n  thrown", ZSTR_VAL(str));
+                       "Uncaught %.*s\n  thrown", PG(log_errors_max_len) ? MIN(ZSTR_LEN(str), MAX(PG(log_errors_max_len) - 18, 0)) : ZSTR_LEN(str), ZSTR_VAL(str));
 
                zend_string_release(str);
                zend_string_release(file);