From 43e3e5390861cebdc9f3c87ebf7ed1414cf9b596 Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 24 Aug 2020 05:22:28 +0000 Subject: [PATCH 1/2] Do not run off end of string when stripping delays, reported by Dave Vandervies. --- tty-term.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tty-term.c b/tty-term.c index 3ccff2ff..5aac1e0c 100644 --- a/tty-term.c +++ b/tty-term.c @@ -302,6 +302,8 @@ tty_term_strip(const char *s) ptr++; if (*ptr == '>') ptr++; + if (*ptr == '\0') + break; } buf[len++] = *ptr; From e4a4fcfc90b09774cb15b030689e977fefe12678 Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 24 Aug 2020 05:23:30 +0000 Subject: [PATCH 2/2] Old Terminal.app versions do not respond correctly to secondary DA, instead responding with the primary DA response. Ignore it. Reported by Dave Vandervies. --- tty-keys.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tty-keys.c b/tty-keys.c index 19ad4f5b..036bd91d 100644 --- a/tty-keys.c +++ b/tty-keys.c @@ -1192,7 +1192,10 @@ tty_keys_device_attributes(struct tty *tty, const char *buf, size_t len, if (tty->flags & TTY_HAVEDA) return (-1); - /* First three bytes are always \033[?. */ + /* + * First three bytes are always \033[>. Some older Terminal.app + * versions respond as for DA (\033[?) so accept and ignore that. + */ if (buf[0] != '\033') return (-1); if (len == 1) @@ -1201,7 +1204,7 @@ tty_keys_device_attributes(struct tty *tty, const char *buf, size_t len, return (-1); if (len == 2) return (1); - if (buf[2] != '>') + if (buf[2] != '>' && buf[2] != '?') return (-1); if (len == 3) return (1); @@ -1219,6 +1222,10 @@ tty_keys_device_attributes(struct tty *tty, const char *buf, size_t len, tmp[i] = '\0'; *size = 4 + i; + /* Ignore DA response. */ + if (buf[2] == '?') + return (0); + /* Convert all arguments to numbers. */ cp = tmp; while ((next = strsep(&cp, ";")) != NULL) {