summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Weinand <bobwei9@hotmail.com>2015-08-18 12:48:06 +0200
committerBob Weinand <bobwei9@hotmail.com>2015-08-18 12:48:06 +0200
commitc83cbdf6cee19914bb9c7722e956ccc8a9cb5a54 (patch)
treef99d9db4eaacaff34108ab45c9b8cb72fb4c13b5
parentd9a9b8572b0064acb5773b795f7deb9cfa8b7a25 (diff)
downloadphp-git-c83cbdf6cee19914bb9c7722e956ccc8a9cb5a54.tar.gz
Better fix for exception traces truncation with anon classes
-rw-r--r--NEWS1
-rw-r--r--Zend/tests/bug69761.phpt3
-rw-r--r--Zend/tests/exception_023.phpt16
-rw-r--r--Zend/zend_exceptions.c9
4 files changed, 24 insertions, 5 deletions
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--
+<?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
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);