diff options
author | Ron Yorston <rmy@pobox.com> | 2021-03-30 13:02:32 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2021-03-30 14:51:27 +0200 |
commit | 24198f652f10dca5603df7c704263358ca21f5ce (patch) | |
tree | e0f20f1a1b1930d7130e68ea6bd0ea547733f95c /editors/vi.c | |
parent | a25b4c2c4245083411011e5054ba859d7c6b8dd6 (diff) | |
download | busybox-w32-24198f652f10dca5603df7c704263358ca21f5ce.tar.gz busybox-w32-24198f652f10dca5603df7c704263358ca21f5ce.tar.bz2 busybox-w32-24198f652f10dca5603df7c704263358ca21f5ce.zip |
vi: deal with invalid movements in shift commands
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@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'editors/vi.c')
-rw-r--r-- | editors/vi.c | 6 |
1 files 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 @@ | |||
7 | */ | 7 | */ |
8 | // | 8 | // |
9 | //Things To Do: | 9 | //Things To Do: |
10 | // EXINIT | ||
11 | // $HOME/.exrc and ./.exrc | 10 | // $HOME/.exrc and ./.exrc |
12 | // add magic to search /foo.*bar | 11 | // add magic to search /foo.*bar |
13 | // add :help command | 12 | // add :help command |
@@ -3574,7 +3573,10 @@ static void do_cmd(int c) | |||
3574 | case '>': // >- Right shift something | 3573 | case '>': // >- Right shift something |
3575 | cnt = count_lines(text, dot); // remember what line we are on | 3574 | cnt = count_lines(text, dot); // remember what line we are on |
3576 | c1 = get_motion_char(); // get the type of thing to operate on | 3575 | c1 = get_motion_char(); // get the type of thing to operate on |
3577 | find_range(&p, &q, c1); | 3576 | if (find_range(&p, &q, c1) == -1) { |
3577 | indicate_error(); | ||
3578 | goto dc6; | ||
3579 | } | ||
3578 | yank_delete(p, q, WHOLE, YANKONLY, NO_UNDO); // save copy before change | 3580 | yank_delete(p, q, WHOLE, YANKONLY, NO_UNDO); // save copy before change |
3579 | p = begin_line(p); | 3581 | p = begin_line(p); |
3580 | q = end_line(q); | 3582 | q = end_line(q); |