From 4634cd47f75e74a697840fb32f18edb7f1cf41da Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Tue, 5 Sep 2017 20:14:33 +0100 Subject: [PATCH] Avoid zero-length ldisc_send() in terminal.c. A user reports that a remote window title query, if the window title is empty or if the option to return it is disabled, fails the assertion in ldisc_send that I introduced as part of commit c269dd013 to catch any lingering uses of ldisc_send with length 0 that should have turned into ldisc_echoedit_update. Added a check for len > 0 guarding that ldisc_send call, and likewise at one or two others I noticed on my way here. (Probably at some point I should decide that the period of smoking out lingering old-style ldisc_send(0) calls is over, and declare it safe to remove that assertion again and get rid of all the cumbersome safety checks at call sites like these ones. But not quite yet.) --- terminal.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/terminal.c b/terminal.c index ba9dd617..f7bcbb95 100644 --- a/terminal.c +++ b/terminal.c @@ -3355,7 +3355,7 @@ static void term_out(Terminal *term) break; case 'Z': /* DECID: terminal type query */ compatibility(VT100); - if (term->ldisc) + if (term->ldisc && term->id_string[0]) ldisc_send(term->ldisc, term->id_string, strlen(term->id_string), 0); break; @@ -3662,7 +3662,7 @@ static void term_out(Terminal *term) case 'c': /* DA: terminal type query */ compatibility(VT100); /* This is the response for a VT102 */ - if (term->ldisc) + if (term->ldisc && term->id_string[0]) ldisc_send(term->ldisc, term->id_string, strlen(term->id_string), 0); break; @@ -4069,7 +4069,8 @@ static void term_out(Terminal *term) p = EMPTY_WINDOW_TITLE; len = strlen(p); ldisc_send(term->ldisc, "\033]L", 3, 0); - ldisc_send(term->ldisc, p, len, 0); + if (len > 0) + ldisc_send(term->ldisc, p, len, 0); ldisc_send(term->ldisc, "\033\\", 2, 0); } break; @@ -4082,7 +4083,8 @@ static void term_out(Terminal *term) p = EMPTY_WINDOW_TITLE; len = strlen(p); ldisc_send(term->ldisc, "\033]l", 3, 0); - ldisc_send(term->ldisc, p, len, 0); + if (len > 0) + ldisc_send(term->ldisc, p, len, 0); ldisc_send(term->ldisc, "\033\\", 2, 0); } break;