aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2016-08-16 15:47:33 +0100
committerRon Yorston <rmy@pobox.com>2016-08-16 15:47:33 +0100
commit977d65c1bbc57f5cdd0c8bfd67c8b5bb1cd390dd (patch)
tree88f2cccab3aa3558f8393617de52d9ccfc0ec3ac
parent31277ab7e6e0a8385a35138d9d2d5168ecadec87 (diff)
downloadbusybox-w32-977d65c1bbc57f5cdd0c8bfd67c8b5bb1cd390dd.tar.gz
busybox-w32-977d65c1bbc57f5cdd0c8bfd67c8b5bb1cd390dd.tar.bz2
busybox-w32-977d65c1bbc57f5cdd0c8bfd67c8b5bb1cd390dd.zip
win32: don't attempt ANSI emulation on data containing NUL characters
-rw-r--r--win32/winansi.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/win32/winansi.c b/win32/winansi.c
index c0493c77e..7069b8d80 100644
--- a/win32/winansi.c
+++ b/win32/winansi.c
@@ -599,20 +599,27 @@ int winansi_get_terminal_width_height(struct winsize *win)
599static int ansi_emulate_write(int fd, const void *buf, size_t count) 599static int ansi_emulate_write(int fd, const void *buf, size_t count)
600{ 600{
601 int rv = 0, i; 601 int rv = 0, i;
602 int special = FALSE, has_null = FALSE;
602 const char *s = (const char *)buf; 603 const char *s = (const char *)buf;
603 char *pos, *str; 604 char *pos, *str;
604 size_t len, out_len; 605 size_t len, out_len;
605 static size_t max_len = 0; 606 static size_t max_len = 0;
606 static char *mem = NULL; 607 static char *mem = NULL;
607 608
608 /* if no special treatment is required output the string as-is */
609 for ( i=0; i<count; ++i ) { 609 for ( i=0; i<count; ++i ) {
610 if ( s[i] == '\033' || s[i] > 0x7f ) { 610 if ( s[i] == '\033' || s[i] > 0x7f ) {
611 break; 611 special = TRUE;
612 }
613 else if ( !s[i] ) {
614 has_null = TRUE;
612 } 615 }
613 } 616 }
614 617
615 if ( i == count ) { 618 /*
619 * If no special treatment is required or the data contains NUL
620 * characters output the string as-is.
621 */
622 if ( !special || has_null ) {
616 return write(fd, buf, count); 623 return write(fd, buf, count);
617 } 624 }
618 625
@@ -626,7 +633,7 @@ static int ansi_emulate_write(int fd, const void *buf, size_t count)
626 mem[count] = '\0'; 633 mem[count] = '\0';
627 pos = str = mem; 634 pos = str = mem;
628 635
629 /* we're writing to the console so we assume the data isn't binary */ 636 /* we've checked the data doesn't contain any NULs */
630 while (*pos) { 637 while (*pos) {
631 pos = strstr(str, "\033["); 638 pos = strstr(str, "\033[");
632 if (pos) { 639 if (pos) {