Skip to content

Commit d5824ce

Browse files
committed
patch 7.4.2326
Problem: Illegal memory access when Visual selection starts in invalid position. (Dominique Pelle) Solution: Correct position when needed.
1 parent 30180b8 commit d5824ce

4 files changed

Lines changed: 28 additions & 0 deletions

File tree

src/misc2.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,28 @@ get_cursor_rel_lnum(
504504
return retval;
505505
}
506506

507+
/*
508+
* Make sure "pos.lnum" and "pos.col" are valid in "buf".
509+
* This allows for the col to be on the NUL byte.
510+
*/
511+
void
512+
check_pos(buf_T *buf, pos_T *pos)
513+
{
514+
char_u *line;
515+
colnr_T len;
516+
517+
if (pos->lnum > buf->b_ml.ml_line_count)
518+
pos->lnum = buf->b_ml.ml_line_count;
519+
520+
if (pos->col > 0)
521+
{
522+
line = ml_get_buf(buf, pos->lnum, FALSE);
523+
len = (colnr_T)STRLEN(line);
524+
if (pos->col > len)
525+
pos->col = len;
526+
}
527+
}
528+
507529
/*
508530
* Make sure curwin->w_cursor.lnum is valid.
509531
*/

src/normal.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9451,7 +9451,10 @@ get_op_vcol(
94519451
#ifdef FEAT_MBYTE
94529452
/* prevent from moving onto a trail byte */
94539453
if (has_mbyte)
9454+
{
9455+
check_pos(curwin->w_buffer, &oap->end);
94549456
mb_adjustpos(curwin->w_buffer, &oap->end);
9457+
}
94559458
#endif
94569459

94579460
getvvcol(curwin, &(oap->start), &oap->start_vcol, NULL, &oap->end_vcol);

src/proto/misc2.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ int dec_cursor(void);
1212
int dec(pos_T *lp);
1313
int decl(pos_T *lp);
1414
linenr_T get_cursor_rel_lnum(win_T *wp, linenr_T lnum);
15+
void check_pos(buf_T *buf, pos_T *pos);
1516
void check_cursor_lnum(void);
1617
void check_cursor_col(void);
1718
void check_cursor_col_win(win_T *win);

src/version.c

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

764764
static int included_patches[] =
765765
{ /* Add new patch number below this line */
766+
/**/
767+
2326,
766768
/**/
767769
2325,
768770
/**/

0 commit comments

Comments
 (0)