summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph M. Becker <cmbecker69@gmx.de>2015-06-17 16:56:04 +0200
committerNikita Popov <nikic@php.net>2015-06-17 22:31:07 +0200
commit653c869348b7626d43a30f67be9362fbcce10d2b (patch)
treedaacc7f819ae0396942f41496d355ab250b19a0d
parent269acaa363cab7de8705b060ba9b1e32322fb0f4 (diff)
downloadphp-git-653c869348b7626d43a30f67be9362fbcce10d2b.tar.gz
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.
-rw-r--r--Zend/tests/bug61362.phpt23
-rw-r--r--Zend/zend_exceptions.c2
2 files changed, 24 insertions, 1 deletions
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--
+<?php
+function test($arg){
+ throw new Exception();
+}
+
+try {
+ test('ั‚ะตัั‚');
+}
+catch(Exception $e) {
+ echo $e->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) {