]> granicus.if.org Git - php/commitdiff
Fix ctrl characters handling
authorBob Weinand <bobwei9@hotmail.com>
Wed, 15 Oct 2014 18:30:16 +0000 (20:30 +0200)
committerBob Weinand <bobwei9@hotmail.com>
Wed, 15 Oct 2014 18:30:16 +0000 (20:30 +0200)
phpdbg_cmd.c
phpdbg_utils.c

index f649bdecf6dfce4f199dba4b8b41ce03ce574047..ad49c62b259a5e18fa97e8d9500b22b7c9893464 100644 (file)
@@ -841,6 +841,14 @@ readline:
                                        }
 
                                        for (i = len; i < len + bytes; i++) {
+                                               if (buf[i] == '\x03') {
+                                                       if (i != len + bytes - 1) {
+                                                               memmove(buf + i, buf + i + 1, len + bytes - i - 1);
+                                                       }
+                                                       len--;
+                                                       i--;
+                                                       continue;
+                                               }
                                                if (buf[i] == '\n') {
                                                        PHPDBG_G(input_buflen) = len + bytes - 1 - i;
                                                        if (PHPDBG_G(input_buflen)) {
index 27b75b24ae40970c242cfa02d4b91b3955ba7e03..41178870f405e443997bd49370ccd13634eb6041 100644 (file)
@@ -1103,7 +1103,11 @@ static void phpdbg_encode_ctrl_chars(char **buf, int *buflen) {
                        len += 4;
                        *tmpptr++ = '&';
                        *tmpptr++ = '#';
-                       *tmpptr++ = ((*buf)[i] / 10) + '0';
+                       if ((unsigned int) buf[i] > 10) {
+                               *tmpptr++ = ((*buf)[i] / 10) + '0';
+                       } else {
+                               --len;
+                       }
                        *tmpptr++ = ((*buf)[i] % 10) + '0';
                        *tmpptr++ = ';';
                } else {
@@ -1373,6 +1377,8 @@ PHPDBG_API int phpdbg_xml_internal(int fd TSRMLS_DC, const char *fmt, ...) {
                buflen = phpdbg_xml_vasprintf(&buffer, fmt, 1, args TSRMLS_CC);
                va_end(args);
 
+               phpdbg_encode_ctrl_chars(&buffer, &buflen);
+
                if (PHPDBG_G(in_script_xml)) {
                        write(fd, ZEND_STRL("</stream>"));
                        PHPDBG_G(in_script_xml) = 0;
@@ -1416,6 +1422,7 @@ PHPDBG_API int phpdbg_out_internal(int fd TSRMLS_DC, const char *fmt, ...) {
                int msglen;
 
                msglen = phpdbg_encode_xml(&msg, buffer, buflen, 256, NULL);
+               phpdbg_encode_ctrl_chars(&msg, &msglen);
 
                if (PHPDBG_G(in_script_xml)) {
                        write(fd, ZEND_STRL("</stream>"));