From b28e3d01d77ee29fc5442d9d0b3d8f06b78b41a1 Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Wed, 15 Oct 2014 20:30:16 +0200 Subject: [PATCH] Fix ctrl characters handling --- phpdbg_cmd.c | 8 ++++++++ phpdbg_utils.c | 9 ++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/phpdbg_cmd.c b/phpdbg_cmd.c index f649bdecf6..ad49c62b25 100644 --- a/phpdbg_cmd.c +++ b/phpdbg_cmd.c @@ -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)) { diff --git a/phpdbg_utils.c b/phpdbg_utils.c index 27b75b24ae..41178870f4 100644 --- a/phpdbg_utils.c +++ b/phpdbg_utils.c @@ -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("")); 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("")); -- 2.40.0