]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
more: fix repeat command
authorKarel Zak <kzak@redhat.com>
Mon, 17 Mar 2025 10:49:57 +0000 (11:49 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 17 Mar 2025 11:19:39 +0000 (12:19 +0100)
The function more_key_command() may modify the current command setting.
We need to remember the original unmodified version, as specified by
the user, as the previous command; otherwise, the output will be affected
by unexpected cmd.number settings.

Simple reproducer:

 $ more -c /etc/passwd

 - Press <enter> to jump to the next line.
 - Press '.' to repeat the last command.

Old version:
 - It clears the screen and prints only one line (like the "1 <enter>" command).
Fixed version:
 - It jumps to the next line (like the "<enter>" command).

Reported-by: Benno Schulenberg <bensberg@telfort.nl>
Signed-off-by: Karel Zak <kzak@redhat.com>
(cherry picked from commit 5be4bdf81a8e89b98b12db275deb6154f87feb4b)

text-utils/more.c

index e39fe724c98a0defbe01e13d14a4cf1c325605a4..ef3011f1bb10a8d8295d7d5e94909f68467f06b9 100644 (file)
@@ -1684,6 +1684,9 @@ static int more_key_command(struct more_control *ctl, char *filename)
                        continue;
                if (cmd.key == more_kc_repeat_previous)
                        cmd = ctl->previous_command;
+               else
+                       ctl->previous_command = cmd;
+
                switch (cmd.key) {
                case more_kc_backwards:
                        if (ctl->no_tty_in) {
@@ -1849,7 +1852,6 @@ static int more_key_command(struct more_control *ctl, char *filename)
                        fflush(NULL);
                        break;
                }
-               ctl->previous_command = cmd;
                if (done) {
                        cmd.key = more_kc_unknown_command;
                        break;