vim-patch:8.0.1486: accessing invalid memory with "it"

Problem:    Accessing invalid memory with "it". (Dominique Pelle)
Solution:   Avoid going over the end of the line. (Christian Brabandt,
            closes vim/vim#2532)
82846a00ac
This commit is contained in:
Jan Edmund Lazo 2018-08-19 23:53:15 -04:00
parent 2c0998e104
commit 1d2b702008
2 changed files with 19 additions and 2 deletions

View File

@ -570,8 +570,12 @@ int searchit(
&& pos->lnum >= 1 && pos->lnum <= buf->b_ml.ml_line_count && pos->lnum >= 1 && pos->lnum <= buf->b_ml.ml_line_count
&& pos->col < MAXCOL - 2) { && pos->col < MAXCOL - 2) {
// Watch out for the "col" being MAXCOL - 2, used in a closed fold. // Watch out for the "col" being MAXCOL - 2, used in a closed fold.
ptr = ml_get_buf(buf, pos->lnum, false) + pos->col; ptr = ml_get_buf(buf, pos->lnum, false);
start_char_len = *ptr == NUL ? 1 : (*mb_ptr2len)(ptr); if ((int)STRLEN(ptr) < pos->col) {
start_char_len = 1;
} else {
start_char_len = utfc_ptr2len(ptr + pos->col);
}
} else { } else {
start_char_len = 1; start_char_len = 1;
} }

View File

@ -152,3 +152,16 @@ func Test_match()
call assert_equal(3 , match('abc', '\zs', 3, 1)) call assert_equal(3 , match('abc', '\zs', 3, 1))
call assert_equal(-1, match('abc', '\zs', 4, 1)) call assert_equal(-1, match('abc', '\zs', 4, 1))
endfunc endfunc
" This was causing an illegal memory access
func Test_inner_tag()
new
norm ixxx
call feedkeys("v", 'xt')
insert
x
x
.
norm it
q!
endfunc