From 020b41dca5e06344f968a46afe122e8043ceecba Mon Sep 17 00:00:00 2001 From: Michael Jennings Date: Tue, 25 Feb 2003 00:37:49 +0000 Subject: [PATCH] Mon Feb 24 19:34:56 2003 Michael Jennings (mej) This fixes the title answer bug reported on BUGTRAQ (and other lists) by HD Moore . It does so by removing all non-printable characters from the title upon setting it, and blanking out all non-printable characters when fetching it to display using the aforementioned escape sequence. SVN revision: 6712 --- ChangeLog | 8 ++++++++ src/term.c | 51 +++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 51 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7ce5b21..72fa428 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4981,3 +4981,11 @@ Patch from Paul Brannan to fix a conflict between twin's non-standard mouse drag reporting and vim when twin support is not enabled. ---------------------------------------------------------------------- +Mon Feb 24 19:34:56 2003 Michael Jennings (mej) + +This fixes the title answer bug reported on BUGTRAQ (and other lists) +by HD Moore . It does so by removing +all non-printable characters from the title upon setting it, and +blanking out all non-printable characters when fetching it to display +using the aforementioned escape sequence. +---------------------------------------------------------------------- diff --git a/src/term.c b/src/term.c index 6ea9031..f3b44e1 100644 --- a/src/term.c +++ b/src/term.c @@ -1316,14 +1316,13 @@ process_xterm_seq(void) void process_window_mode(unsigned int nargs, int args[]) { - register unsigned int i; int x, y; Screen *scr; Window dummy_child; int dummy_x, dummy_y; unsigned int dummy_border, dummy_depth; - char buff[1024], *name; + char buff[1024], *name, *ptmp; if (!nargs) return; @@ -1398,12 +1397,30 @@ process_window_mode(unsigned int nargs, int args[]) break; case 20: XGetIconName(Xdisplay, TermWin.parent, &name); + for (ptmp = name; *ptmp; ptmp++) { + if (ptmp - name > 4096) { + *ptmp = 0; + break; + } + if (*ptmp < 32) { + *ptmp = ' '; + } + } snprintf(buff, sizeof(buff), "\033]L%s\033\\", name); tt_write((unsigned char *) buff, strlen(buff)); XFree(name); break; case 21: XFetchName(Xdisplay, TermWin.parent, &name); + for (ptmp = name; *ptmp; ptmp++) { + if (ptmp - name > 4096) { + *ptmp = 0; + break; + } + if (*ptmp < 32) { + *ptmp = ' '; + } + } snprintf(buff, sizeof(buff), "\033]l%s\033\\", name); tt_write((unsigned char *) buff, strlen(buff)); XFree(name); @@ -1721,12 +1738,21 @@ set_title(const char *str) str = APL_NAME "-" VERSION; } if (name == NULL || strcmp(name, str)) { + char *pname, *pstr; + if (name != NULL) { FREE(name); } - D_X11(("Setting window title to \"%s\"\n", str)); - XStoreName(Xdisplay, TermWin.parent, str); - name = STRDUP(str); + name = MALLOC(strlen(str)); + + for (pname = name, pstr = str; *pstr; pstr++) { + if (*pstr >= 32) { + *pname++ = *pstr; + } + } + *pname = 0; + D_X11(("Setting window title to \"%s\"\n", name)); + XStoreName(Xdisplay, TermWin.parent, name); } } @@ -1738,12 +1764,21 @@ set_icon_name(const char *str) if (!str) str = APL_NAME "-" VERSION; if (name == NULL || strcmp(name, str)) { + char *pname, *pstr; + if (name != NULL) { FREE(name); } - D_X11(("Setting window icon name to \"%s\"\n", str)); - XSetIconName(Xdisplay, TermWin.parent, str); - name = STRDUP(str); + name = MALLOC(strlen(str)); + + for (pname = name, pstr = str; *pstr; pstr++) { + if (*pstr >= 32) { + *pname++ = *pstr; + } + } + *pname = 0; + D_X11(("Setting window icon name to \"%s\"\n", name)); + XSetIconName(Xdisplay, TermWin.parent, name); } }