File: more-fix-implicit-previous-shell_line-execution-3508.patch

package info (click to toggle)
util-linux 2.41-5
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 95,208 kB
  • sloc: ansic: 179,016; sh: 22,689; yacc: 1,284; makefile: 528; xml: 422; python: 316; lex: 89; ruby: 75; csh: 37; exp: 19; sed: 16; perl: 15; sql: 9
file content (64 lines) | stat: -rw-r--r-- 2,299 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
From: cgoesche <cgoesc2@wgu.edu>
Date: Sat, 5 Apr 2025 01:29:35 -0400
Subject: more: fix implicit previous shell_line execution #3508

run_shell() will implicitly execute the previous ctl->shell_line
not only if the function was indirectly invoked by the '.' command
but also by a subsequent '!' command.

Addresses: #3508
Signed-off-by: Christian Goeschel Ndjomouo <cgoesc2@wgu.edu>
(cherry picked from commit b6f9362988dbe5427d52b31ac3add37a7ddb6b12)
---
 text-utils/more.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/text-utils/more.c b/text-utils/more.c
index a035591..f80aeff 100644
--- a/text-utils/more.c
+++ b/text-utils/more.c
@@ -226,6 +226,7 @@ struct more_control {
 		print_banner,  		/* print file name banner */
 		reading_num,  		/* are we reading leading_number */
 		report_errors,  	/* is an error reported */
+		prev_command_called,	/* previous more command is called */
 		search_at_start,  	/* search pattern defined at start up */
 		search_called,  	/* previous more command was a search */
 		squeeze_spaces,  	/* suppress white space */
@@ -1295,8 +1296,11 @@ static void run_shell(struct more_control *ctl, char *filename)
 	erase_to_col(ctl, 0);
 	putchar('!');
 	fflush(NULL);
-	if (ctl->previous_command.key == more_kc_run_shell && ctl->shell_line)
+	if (ctl->previous_command.key == more_kc_run_shell && ctl->shell_line
+	    && ctl->prev_command_called == 1) {
 		fputs(ctl->shell_line, stderr);
+		ctl->prev_command_called = 0;
+	}
 	else {
 		ttyin(ctl, cmdbuf, sizeof(cmdbuf) - 2, '!');
 		if (strpbrk(cmdbuf, "%!\\"))
@@ -1674,6 +1678,7 @@ static int more_key_command(struct more_control *ctl, char *filename)
 	else
 		ctl->report_errors = 0;
 	ctl->search_called = 0;
+	ctl->prev_command_called = 0;
 	for (;;) {
 		if (more_poll(ctl, -1, &stderr_active) <= 0)
 			continue;
@@ -1682,10 +1687,13 @@ static int more_key_command(struct more_control *ctl, char *filename)
 		cmd = read_command(ctl);
 		if (cmd.key == more_kc_unknown_command)
 			continue;
-		if (cmd.key == more_kc_repeat_previous)
+		if (cmd.key == more_kc_repeat_previous) {
 			cmd = ctl->previous_command;
-		else
+			ctl->prev_command_called = 1;
+		}
+		else {
 			ctl->previous_command = cmd;
+		}
 
 		switch (cmd.key) {
 		case more_kc_backwards: