From 653c869348b7626d43a30f67be9362fbcce10d2b Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Wed, 17 Jun 2015 16:56:04 +0200 Subject: [PATCH] Fix #61362: Exception::getTraceAsString and ::__toString scramble Unicode The logic in smart_str_append_escaped() relies on unsigned values of c, so we have to declare it as such. --- Zend/tests/bug61362.phpt | 23 +++++++++++++++++++++++ Zend/zend_exceptions.c | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 Zend/tests/bug61362.phpt diff --git a/Zend/tests/bug61362.phpt b/Zend/tests/bug61362.phpt new file mode 100644 index 0000000000..af216b566f --- /dev/null +++ b/Zend/tests/bug61362.phpt @@ -0,0 +1,23 @@ +--TEST-- +Bug #61362 (Exception::getTraceAsString, Exception::__toString not able to handle unicode) +--FILE-- +getTraceAsString(), "\n"; + echo (string)$e; +} +?> +--EXPECTF-- +#0 %s(%d): test('\xD1\x82\xD0\xB5\xD1\x81\xD1\x82') +#1 {main} +Exception in %s:%d +Stack trace: +#0 %s(%d): test('\xD1\x82\xD0\xB5\xD1\x81\xD1\x82') +#1 {main} diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index e731e21718..cf18084ff5 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -427,7 +427,7 @@ static void smart_str_append_escaped(smart_str *str, const char *s, size_t l) { str->s->len += len; for (i = 0; i < l; ++i) { - char c = s[i]; + unsigned char c = s[i]; if (c < 32 || c == '\\' || c > 126) { *res++ = '\\'; switch (c) { -- 2.40.0