]> 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 10:49:57 +0000 (11:49 +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>
text-utils/more.c

index 48f27f9e9abfd0cc24de519d75ff42c001059af6..a035591af306bb86e71c93a618e15f82b326b7a6 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;