]> git.tue.mpg.de Git - paraslash.git/commitdiff
i9e: Fix invalid key handling.
authorAndre Noll <maan@tuebingen.mpg.de>
Mon, 25 Jul 2022 22:08:43 +0000 (00:08 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Sun, 21 Aug 2022 15:14:06 +0000 (17:14 +0200)
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

index 4819e1c737032bdc62de06a40f351263734e0911..9f4dec175caf12c9ff3bf9ad30b2c90281a9828e 100644 (file)
@@ -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)