From 4c1f0ea9b7b5174d86a99803c1563caf778a8ee2 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Tue, 26 Jul 2022 00:08:43 +0200 Subject: [PATCH] i9e: Fix invalid key handling. If an unmapped key is pressed repeatedly, we store the key sequence in a 32 byte buffer until there is no more space left in the buffer. Then we terminate the process with para_play: interactive.c:304: i9e_post_monitor: Assertion `len < sizeof(i9ep->key_sequence) - 1' failed. This is not a nice way to deal with invalid input, so be a bit more graceful and discard the buffer when it is full or when there is no further input available at the moment. --- interactive.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/interactive.c b/interactive.c index 4819e1c7..9f4dec17 100644 --- a/interactive.c +++ b/interactive.c @@ -312,23 +312,27 @@ static int i9e_post_select(__a_unused struct sched *s, __a_unused void *context) goto rm_btrn; while (input_available()) { if (i9ep->stdout_btrn) { - unsigned len = i9ep->key_sequence_length; - assert(len < sizeof(i9ep->key_sequence) - 1); - buf = i9ep->key_sequence + len; - ret = read(i9ep->ici->fds[0], buf, 1); - if (ret < 0) { - ret = -ERRNO_TO_PARA_ERROR(errno); - goto rm_btrn; + while (i9ep->key_sequence_length < sizeof(i9ep->key_sequence) - 1) { + buf = i9ep->key_sequence + i9ep->key_sequence_length; + ret = read(i9ep->ici->fds[0], buf, 1); + if (ret < 0) { + ret = -ERRNO_TO_PARA_ERROR(errno); + goto rm_btrn; + } + if (ret == 0) { + ret = -E_I9E_EOF; + goto rm_btrn; + } + buf[1] = '\0'; + i9ep->key_sequence_length++; + rl_stuff_char((int)(unsigned char)*buf); + rl_callback_read_char(); + if (!input_available()) + break; } - if (ret == 0) { - ret = -E_I9E_EOF; - goto rm_btrn; - } - buf[1] = '\0'; - i9ep->key_sequence_length++; - rl_stuff_char((int)(unsigned char)*buf); - } - rl_callback_read_char(); + i9ep->key_sequence_length = 0; + } else + rl_callback_read_char(); ret = 0; } if (!i9ep->stdout_btrn) -- 2.39.2