Skip to content

Commit 5c838a3

Browse files
committed
patch 8.0.0841: term_getline() may cause a crash
Problem: term_getline() may cause a crash. Solution: Check that the row is valid. (Hirohito Higashi)
1 parent b6843a0 commit 5c838a3

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

src/terminal.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1847,6 +1847,8 @@ f_term_getline(typval_T *argvars, typval_T *rettv)
18471847
int len;
18481848
char_u *p;
18491849

1850+
if (row < 0 || row >= term->tl_rows)
1851+
return;
18501852
len = term->tl_cols * MB_MAXBYTES + 1;
18511853
p = alloc(len);
18521854
if (p == NULL)

src/testdir/test_terminal.vim

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ func Test_terminal_hide_buffer()
8181
endfunc
8282

8383
func Check_123(buf)
84+
let l = term_scrape(a:buf, 0)
85+
call assert_true(len(l) == 0)
86+
let l = term_scrape(a:buf, 999)
87+
call assert_true(len(l) == 0)
8488
let l = term_scrape(a:buf, 1)
8589
call assert_true(len(l) > 0)
8690
call assert_equal('1', l[0].chars)
@@ -93,6 +97,12 @@ func Check_123(buf)
9397
call assert_equal('#000000', l[0].bg)
9498
endif
9599

100+
let l = term_getline(a:buf, -1)
101+
call assert_equal('', l)
102+
let l = term_getline(a:buf, 0)
103+
call assert_equal('', l)
104+
let l = term_getline(a:buf, 999)
105+
call assert_equal('', l)
96106
let l = term_getline(a:buf, 1)
97107
call assert_equal('123', l)
98108
endfunc

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,8 @@ static char *(features[]) =
769769

770770
static int included_patches[] =
771771
{ /* Add new patch number below this line */
772+
/**/
773+
841,
772774
/**/
773775
840,
774776
/**/

0 commit comments

Comments
 (0)