From c83cbdf6cee19914bb9c7722e956ccc8a9cb5a54 Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Tue, 18 Aug 2015 12:48:06 +0200 Subject: [PATCH] Better fix for exception traces truncation with anon classes --- NEWS | 1 + Zend/tests/bug69761.phpt | 3 ++- Zend/tests/exception_023.phpt | 16 ++++++++++++++++ Zend/zend_exceptions.c | 9 +++++---- 4 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 Zend/tests/exception_023.phpt diff --git a/NEWS b/NEWS index 6a921d358b..ea83714e2f 100644 --- 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). diff --git a/Zend/tests/bug69761.phpt b/Zend/tests/bug69761.phpt index 4b7e2787d8..2ec7cc10e1 100644 --- a/Zend/tests/bug69761.phpt +++ b/Zend/tests/bug69761.phpt @@ -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 index 0000000000..34de77a476 --- /dev/null +++ b/Zend/tests/exception_023.phpt @@ -0,0 +1,16 @@ +--TEST-- +Ensure proper backtraces with anon classes +--FILE-- + +--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 diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index 307589b5fe..3af0b5ac07 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -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); -- 2.50.0