[git commit] vi: deal with invalid movements in shift commands

Denys Vlasenko vda.linux at googlemail.com
Tue Mar 30 12:51:27 UTC 2021


commit: https://git.busybox.net/busybox/commit/?id=24198f652f10dca5603df7c704263358ca21f5ce
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master

Since commit 25d259264 (vi: make buffer handling more vi-like)
find_range() can return early when an invalid movement is
specified.

The call to find_range() in the code that handles shift commands
('<' and '>') doesn't check for this condition.  Previously this
only resulted in the current line being shifted but it can now
result in a segfault.

Check for an invalid movement and notify the user without taking
any further action.

function                                             old     new   delta
do_cmd                                              4890    4898      +8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 8/0)                 Total: 8 bytes

Signed-off-by: Ron Yorston <rmy at pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 editors/vi.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/editors/vi.c b/editors/vi.c
index 4fa67a110..04d584fec 100644
--- a/editors/vi.c
+++ b/editors/vi.c
@@ -7,7 +7,6 @@
  */
 //
 //Things To Do:
-//	EXINIT
 //	$HOME/.exrc  and  ./.exrc
 //	add magic to search	/foo.*bar
 //	add :help command
@@ -3574,7 +3573,10 @@ static void do_cmd(int c)
 	case '>':			// >- Right shift something
 		cnt = count_lines(text, dot);	// remember what line we are on
 		c1 = get_motion_char();	// get the type of thing to operate on
-		find_range(&p, &q, c1);
+		if (find_range(&p, &q, c1) == -1) {
+			indicate_error();
+			goto dc6;
+		}
 		yank_delete(p, q, WHOLE, YANKONLY, NO_UNDO);	// save copy before change
 		p = begin_line(p);
 		q = end_line(q);


More information about the busybox-cvs mailing list