]> granicus.if.org Git - php/commitdiff
Fix #61362: Exception::getTraceAsString and ::__toString scramble Unicode
authorChristoph M. Becker <cmbecker69@gmx.de>
Wed, 17 Jun 2015 14:56:04 +0000 (16:56 +0200)
committerNikita Popov <nikic@php.net>
Wed, 17 Jun 2015 20:31:07 +0000 (22:31 +0200)
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 [new file with mode: 0644]
Zend/zend_exceptions.c

diff --git a/Zend/tests/bug61362.phpt b/Zend/tests/bug61362.phpt
new file mode 100644 (file)
index 0000000..af216b5
--- /dev/null
@@ -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}
index e731e2171828fb6bcb712164900597cff064a126..cf18084ff5be2685555d5b2da4b54ff37e58af13 100644 (file)
@@ -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) {