From: Christoph M. Becker Date: Wed, 17 Jun 2015 14:56:04 +0000 (+0200) Subject: Fix #61362: Exception::getTraceAsString and ::__toString scramble Unicode X-Git-Tag: php-7.0.0alpha2~2^2~94 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=653c869348b7626d43a30f67be9362fbcce10d2b;p=php 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. --- 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) {