From f41dc91357701bd8708e48dc38ff909b3639720f Mon Sep 17 00:00:00 2001
From: nicm <nicm>
Date: Fri, 28 Mar 2025 17:15:25 +0000
Subject: [PATCH] Only copy the key string not two bytes extra, found by David
 Mandelberg.

---
 tty-keys.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tty-keys.c b/tty-keys.c
index 7b0da5a2..f78b84f2 100644
--- a/tty-keys.c
+++ b/tty-keys.c
@@ -1061,8 +1061,8 @@ tty_keys_extended_key(struct tty *tty, const char *buf, size_t len,
 		return (-1);
 
 	/* Copy to the buffer. */
-	memcpy(tmp, buf + 2, end);
-	tmp[end] = '\0';
+	memcpy(tmp, buf + 2, end - 2);
+	tmp[end - 2] = '\0';
 
 	/* Try to parse either form of key. */
 	if (buf[end] == '~') {